我正在寻找一种通过outlook.interop在c#中发送电子邮件的方法,没有任何弹出窗口或安全警告。我使用此代码获取受信任的应用程序对象https://msdn.microsoft.com/en-us/library/office/ff869819.aspx ...
private void EmailMessage(string recipient, string subject, string body)
{
Microsoft.Office.Interop.Outlook.Application application = GetApplication();
Microsoft.Office.Interop.Outlook.MailItem email = (Outlook.MailItem)application.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);
try
{
email.Subject = subject;
email.Body = body;
email.To = recipient;
((Outlook._MailItem)email).Send();
_emailConfirmation = true;
}
catch (System.Runtime.InteropServices.COMException ex)
{
_emailConfirmation = false;
}
catch (Exception ex)
{
_emailConfirmation = false;
}
finally
{
//release the objects used to send email after message has been sent\\
if (email != null)
System.Runtime.InteropServices.Marshal.ReleaseComObject(email);
if (application != null)
System.Runtime.InteropServices.Marshal.ReleaseComObject(application);
}
}
此代码用于发送电子邮件,但由于outlook安全管理器,它仍然会提示用户。任何修复的想法,以便用户不会有任何中断或与outlook的交互?
答案 0 :(得分:0)
有关选项列表,请参阅http://www.outlookcode.com/article.aspx?id=52。 基本上你可以。