我有一个 C# 程序来发送邮件。 很少有过程调用 mailItem.send() 没有错误,但 Outlook 不发送邮件,并且邮件不是在 Outlook“发送”文件夹中创建的。
如何检测?
代码如下:
private void sendMail(String mail, String description)
{
RegistryKey key = Registry.ClassesRoot;
RegistryKey subKey = key.OpenSubKey("Outlook.Application");
if (subKey != null)
{
if ((Process.GetProcessesByName("Outlook").Length == 0) && (Process.GetProcessesByName("Outlook.exe").Length == 0))
{
System.Diagnostics.Process.Start("Outlook");
}
Microsoft.Office.Interop.Outlook.Application app = new Microsoft.Office.Interop.Outlook.Application();
Microsoft.Office.Interop.Outlook.MailItem mailItem = app.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);
mailItem.Subject = "Release Notice";
mailItem.To = mail;
String bodyMessage = description;
mailItem.Body = bodyMessage;
mailItem.Display(false);
mailItem.Send();
}
else
{
MessageBox.Show("Impossible to send mails. Contact system administrator.", "System Info", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
最佳答案
如果您的 send()
方法没有发送任何错误或异常,那么您很可能无法检测到是否存在任何错误/异常(至少从您的代码中 )
一旦您的邮件被移动到 Outlook 服务器,您就无法检查状态。您必须依靠 Outlook 服务器来发送您的电子邮件。
您可以引用 Jeff Atwood 的这篇文章:So You'd Like to Send Some Email
关于c# - "Office.Interop.Outlook"不发送邮件时检测,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35038026/