【问题标题】:How to reply to an Outlook mailitem using .net如何使用 .net 回复 Outlook 邮件项
【发布时间】:2013-04-27 05:41:03
【问题描述】:

我正在编写一个 Outlook 2007 加载项,该加载项组成一个商业报价以响应电子邮件查询。我使用 Windows 表单撰写报价单。一切正常,直到我用报价信息回复原始消息。

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 的异常。错误是

'找不到对象'

。 我需要做的是添加和删除收件人,并在发送之前在报价单上设置 CCBCC 字段。收件人可能不在通讯录中。我已经用其他邮件库做到了这一点,它应该很简单,但我似乎为 Outlook 找错了树。

编辑找到了 - 感谢 Dmitry 为我指明了正确的方向。

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

【问题讨论】:

  • 如果dimitry的回答是正确的,请评分并采纳:)
  • 问题不在于 Dmitry 的回答中提供的地址解析,但他确实让我进入了我感谢他的文档的正确区域。

标签: c# outlook ms-office office-interop office-2007


【解决方案1】:

必须先解析收件人。而且您不能设置 AddressEntry.Address 属性 - 即使它是可设置的,它也不会指向消息收件人表。

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

【讨论】:

  • 谢谢 Dmitry - 我是不是要推断收件人必须在通讯簿中,Outlook 才会向他发送邮件?
  • 否,“Joe Blow ”将被解析为一次性 SMTP 收件人。这与在 Outlook 的“收件人”编辑框中手动键入地址并按 Ctrl+K 来解决它没有任何不同。
猜你喜欢
  • 2021-05-22
  • 2019-05-06
  • 2016-10-20
  • 2016-10-16
  • 1970-01-01
  • 1970-01-01
  • 2017-11-04
  • 2011-11-26
  • 2015-10-27
相关资源
最近更新 更多