3
votes

I have a WinForms app that at the click of a button automatically produces an Outlook mail as follows:

public static void CreateOutlookEmail(string pFileName, string pCaseFolder, string pEmail, string pSubject, string pMessage)
    {
        try
        {
            Outlook.Application outlookApp = new Outlook.Application();
            Outlook.MailItem mailItem = (Outlook.MailItem)outlookApp.CreateItem(Outlook.OlItemType.olMailItem);                
            mailItem.Subject = pSubject;
            mailItem.To = pEmail;
            mailItem.Body = pMessage;
            mailItem.Importance = Outlook.OlImportance.olImportanceNormal;
            mailItem.Display(false);
            string fileDetails = pCaseFolder + "\\" + pFileName + @".eml";
            mailItem.SaveAs(fileDetails);
        }
        catch (Exception eX)
        {
            throw new Exception("cDocument: Error occurred trying to Create an Outlook Email"
                                + Environment.NewLine + eX.Message);
        }
    }

The code succesfully opens a new Outlook email, and populates it with the details sent into the method e.g. email address, subject and the body of the message.

Also when I locate the folder (sent in as a paramater) I can see the email document has been saved.

The issue is, that when I open the email from the folder, the email document is totaly blank ii.e. no email address, subject or message.

What am I doing wrong?

1

1 Answers

0
votes

Your code is fine. Just use extension ".msg" instead of ".eml". Also the eml format does not exist under Outlook.OlSaveAsType