我想在用戶提交表單時發送確認電子郵件。我有smtp privlage問題,所以我想通過Outlook來做到這一點。當Outlook未打開時,代碼正常工作enter link description here,但只是掛起。任何想法如何解決這個或周圍的方式?當Outlook打開時,Microsoft.Office.Interop.Outlook確認電子郵件不起作用
try
{
// Create the Outlook application.
Outlook.Application oApp = new Outlook.Application();
// Create a new mail item.
Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
// Set HTMLBody.
//add the body of the email
oMsg.HTMLBody = "Hello, Jawed your message body will go here!!";
//Subject line
oMsg.Subject = "Your Subject will go here.";
// Add a recipient.
Outlook.Recipients oRecips = (Outlook.Recipients)oMsg.Recipients;
// Change the recipient in the next line if necessary.
Outlook.Recipient oRecip = (Outlook.Recipient)oRecips.Add("[email protected]");
oRecip.Resolve();
// Send.
((Outlook._MailItem)oMsg).Send();
// Clean up.
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(oMsg);
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(oRecip);
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(oRecips);
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(oApp);
}//end of try block
catch (Exception ex)
{
}//end of catch
您是否嘗試過檢查,看看是否Outlook的現有實例是開放的,使用它,如果有一個,那麼如果沒有一個創建新實例? –
我的合約上有一個實例打開。我不知道我將如何使用該實例 – joetinger