【问题标题】:c# forward Email from Outlook inboxc# 从 Outlook 收件箱转发电子邮件
【发布时间】:2018-04-04 18:27:27
【问题描述】:

我想转发 Outlook 收件箱文件夹中的现有电子邮件。在最近的研究中,我发现了一些不同的解决方案:

  • 获取当前邮件项并将其复制到新邮件中
  • move 方法在不同的文件夹中移动
  • 转发方法...

我的目标是找到一种简单的方法将现有电子邮件转发到另一个电子邮件地址

我附上的代码没有有权发送!

private void buttonExplorer_Click(object sender, RibbonControlEventArgs e)
{
    Microsoft.Office.Interop.Outlook.Selection mySelection = Globals.ThisAddIn.Application.ActiveExplorer().Selection;
    Microsoft.Office.Interop.Outlook.MailItem mailItem = null;
    foreach (Object obj in mySelection)
    {
        if (obj is Microsoft.Office.Interop.Outlook.MailItem)
        {
            mailItem = (Microsoft.Office.Interop.Outlook.MailItem)obj;
            mailItem.Forward();
            mailItem.Recipients.Add("test@web.com");
            mailItem.Send();
        }
    }
}

如果有解决转发事件问题的简单方法会很好。

【问题讨论】:

    标签: c# email outlook forwarding


    【解决方案1】:

    Forward() 创建一个新项目,如 here 所述。

    因此,从那时起您将需要使用该新项目:

    var newItem = mailItem.Forward();
    newItem.Recipients.Add("to.alt@web.de");
    newItem.Send();
    

    【讨论】:

    • 完美!谢谢。你知道附件是否会一起发送吗?
    • 刚刚测试 - 附件已成功复制并发送
    【解决方案2】:

    尝试使用 Microsoft Exchange Web 服务 (EWS) 转发电子邮件。 EWS为常用事件提供了api。

    这样的示例代码,

    // Connect to Exchange Web Services as user1 at contoso.com.
    ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
    service.Credentials = new WebCredentials("user1@contoso.com", "password ");
    service.AutodiscoverUrl("user1@contoso.com");
    
    // Create the e-mail message, set its properties, and send it to user2@contoso.com, saving a copy to the Sent Items folder. 
    EmailMessage message = new EmailMessage(service);
    message.Subject = "Interesting";
    message.Body = "The proposition has been considered."; 
    message.ToRecipients.Add("user2@contoso.com");
    message.SendAndSaveCopy();
    

    更多信息,请参考https://msdn.microsoft.com/en-us/library/office/dd633681(v=exchg.80).aspx

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-01-07
      • 1970-01-01
      • 1970-01-01
      • 2020-05-30
      • 1970-01-01
      • 2023-03-10
      • 1970-01-01
      • 2022-08-20
      相关资源
      最近更新 更多