1
votes

I'm stuck with this. Here is my sample Code. I want to create a mail item and bind it from database like a mail message. and then i want to reply it with outlook' s reply pattern. adding from:, to:, that horizontal line, etc.etc. above theoriginal mail.. but it' s not working for created mail like "Globals.ThisAddIn.Application.CreateItem(OlItemType.olMailItem) as MailItem"

MailItem.Reply() is working perfectly when the MailItem is one of the Globals.ThisAddIn.Application.ActiveExplorer().Selection Items what am i missing here?

thanks..

            MailItem oItem = Globals.ThisAddIn.Application.CreateItem(OlItemType.olMailItem) as MailItem;
            oItem.Body = "...";
            oItem.To = "[email protected]";
            oItem.CC = "[email protected]";
            oItem.Subject = "....";
            MailItem response = oItem.Reply();

Error Codes Here: An exception of type 'System.Runtime.InteropServices.COMException' occurred in HMOutlookAddIn.dll but was not handled in user code

Additional information: Could not send mail.

Error Code: -2147352567

1

1 Answers

0
votes

There is no need to reply to newly created items. The Reply method can be used against recieved messages only.

Instead, you need to use the Send method of the MailItem class.

    mail = OutlookApp.CreateItem(Outlook.OlItemType.olMailItem)
       as Outlook.MailItem;
    mail.Subject = "A programatically generated e-mail";
    mailRecipients = mail.Recipients;
    mailRecipient = mailRecipients.Add("Eugene Astafiev");
    mailRecipient.Resolve();
    if (mailRecipient.Resolved)
    {
        mail.Send();
    }
    else
    {
        System.Windows.Forms.MessageBox.Show(
            "There is no such record in your address book.");
    }

You may find the following articles helpful: