How to reply to an Outlook mailitem using .net

二次信任 提交于 2019-12-25 01:44:39

问题


I am writing an Outlook 2007 Add-in which composes a business quote in response to an email query. I compose the quote using Windows forms. Everything works fine until I get to the point of replying to the original message with the quote information.

private void btnSend_Click(object sender, EventArgs e) 
{
    Outlook.MailItem theMail = ((Outlook._MailItem)quote.mailItem).Reply();
    theMail.Subject = "This is the quote";
    theMail.Body = <Some html composed elsewhere>;

    Outlook.Recipient rcp = theMail.Recipients.Add("Joe Blow");
    Outlook.AddressEntry ae = rcp.AddressEntry;
    ae.Address = "joe@blow.com";
}

Where quote.mailItem is the incoming email request. When I run the code, it throws an exception executing rcp.AddressEntry. The error is

'An object cannot be found'

. What I need to be able to do is add and delete addressees as well as setting CC and BCC fields on the quote before I send it out. Addressees may not be in the address book. I have done this with other mail libraries and it should be simple, but I seem to be barking up the wrong tree for Outlook.

EDIT Found it - thanks Dmitry for pointing me in the right direction.

Outlook.Recipient rcp = theMail.Recipients.Add("joe blow <joe@blow.com>");
rcp.Type = (int)Outlook.OlMailRecipientType.olTo;

回答1:


The recipient must be resolved first . And you cannot set the AddressEntry.Address property - even if it were settable, it does not point back to the message recipients table.

Outlook.Recipient rcp = theMail.Recipients.Add("Joe Blow <joe@blow.com>");
rcp.Resolve();


来源:https://stackoverflow.com/questions/16348403/how-to-reply-to-an-outlook-mailitem-using-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!