I am using the following code to send emails using Outlook:
private static void SendMailItem(string from, string to, string subject, string body, string attachment = null)
{
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 = subject;
mailItem.To = to;
mailItem.Body = body;
if (attachment != null)
{
mailItem.Attachments.Add(attachment, Microsoft.Office.Interop.Outlook.OlAttachmentType.olByValue);
}
mailItem.Importance = Microsoft.Office.Interop.Outlook.OlImportance.olImportanceHigh;
mailItem.Display(false);
mailItem.Send();
}
It works almost perfectly, but I run into a problem when trying to send an email without a subject. The following dialog box pops up:
I want to skip this prompt or automatically accept (send anyway). How do I achieve this?
Comment out the mailItem.Display(false);
line.