如何使用.net答复Outlook mailitem [英] How to reply to an Outlook mailitem using .net

查看:90
本文介绍了如何使用.net答复Outlook mailitem的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个Outlook 2007加载项,该加载项构成了对电子邮件查询的业务报价.我使用Windows窗体撰写报价.一切正常,直到我得到包含报价信息的原始消息的回复为止.

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";
}

其中quote.mailItem是传入的电子邮件请求.当我运行代码时,它将引发执行rcp.AddressEntry的异常.错误是

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'

. 我需要做的就是添加和删除收件人,并在报价发送前在报价上设置 CC BCC 字段.收件人可能不在通讯簿中.我已经使用其他邮件库完成了此操作,这应该很简单,但是我似乎为Outlook弄错了树.

. 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.

编辑找到了它-感谢德米特里(Dmitry)向我指出了正确的方向.

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;

推荐答案

必须先解决收件人.而且您无法设置AddressEntry.Address属性-即使它是可设置的,它也不会指向邮件收件人表.

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();

这篇关于如何使用.net答复Outlook mailitem的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆