Jitesh Dammani
Jitesh Dammani

Reputation: 81

ReplyAll() function not working in Microsoft Outlook

private void CreateEmailItem()
{
    Object selObject = this.Application.ActiveExplorer().Selection[1];
    string sendernames = (selObject as Outlook._MailItem).SenderName;
    Outlook._MailItem eMail = (Outlook._MailItem)
    this.Application.CreateItem(Outlook.OlItemType.olMailItem);
    eMail = selObject as Outlook._MailItem;
    ((Outlook._MailItem)eMail).Body = "Approved";
    ((Outlook._MailItem)eMail).ReplyAll();
}

If we instead use ((Outlook._MailItem)eMail).Send(); its working, but while using ReplyAll() function its not working.

Upvotes: 0

Views: 630

Answers (2)

Eugene Astafiev
Eugene Astafiev

Reputation: 49455

There is no need to create a new mail item from scratch. Instead, you can use an item which is returned from the ReplyAll method. So, you can take the selected item in the Explorer window and cast it to a MailItem class.

Object selObject = this.Application.ActiveExplorer().Selection[1];
Outlook._MailItem eMail = selObject as Outlook._MailItem;
Outlook._MailItem reply = eMail.ReplyAll();

After you can deal with the reply object and set its properties according to your needs.

You may find the How To: Respond to an Outlook email programmatically article helpful.

Upvotes: 2

Dmitry Streblechenko
Dmitry Streblechenko

Reputation: 66286

ReplyAll is a function that returns the newly created item. Your code above ignores the returned value and sets the Body property on the original item.

Upvotes: 1

Related Questions