• Subject: Outlook automation SaveAs method hangs
  • Author: Yashgt
  • Date: 29 May
  • References:
Hi,

We are trying to programmtically build a MailItem object in a .NET
program and trying to save it as a .msg file. The code works up to the
point of the SaveAs call, where it hangs indefinitely. What could be
the issue? Please see the code below. We have ensured that no other
instance of Outlook.exe is running when we run our program.

Outlook.Application OutlookApplication = new Outlook.Application();
Outlook.NameSpace olNamespace =
OutlookApplication.GetNamespace("MAPI");
olNamespace.Logon(null, null, false, false);

Outlook.MailItem newMail =
(Outlook.MailItem)OutlookApplication.CreateItem(Outlook.OlItemType.olMailItem);
newMail.To = "abc@xyz.com";
newMail.Subject = objEmailQueueLog.EmailTemplateSubject;
newMail.Body = objEmailQueueLog.EmailTemplateBody;
newMail.SaveAs(@"C:\aa.msg", Outlook.OlSaveAsType.olMSG);
newMail = null;
olNamespace.Logoff();
olNamespace = null;

Thanks,
Yash
29 MayOutlook automation SaveAs method hangs.Yashgt
All times are in (US) Eastern Daylight Time (GMT -4:00)