我想在用户提交表单时发送确认电子邮件。我有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