Reputation: 13920
I have a c# procedure to send mails. Rarely the procedure call mailItem.send() without error but Outlook don't send the mail, and mail isn't create in Outlook "to send" folder.
How to detect this ?
The code is the follow:
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);
}
}
Upvotes: 3
Views: 1386
Reputation: 172458
If your send()
method is not sending any error or exception then its quite possible that you cannot detect if there is any error/exception(atleast from your code)
Once your message is moved to the Outlook server then it is out of your reach to check the status. You have to rely on the Outlook server to send your email.
You can refer this article by Jeff Atwood: So You'd Like to Send Some Email
Upvotes: 2