c# 从 Outlook 收件箱转发电子邮件
c# forward Email from Outlook inbox
我想转发我的 Outlook 收件箱文件夹中的现有电子邮件。在最近的研究中,我发现了一些不同的解决方案:
- 获取当前邮件项目并将其复制到新邮件中
- 移动方法移动到不同的文件夹
- 转发方法...
我的目标是找到一种简单的方法将现有电子邮件转发到另一个 电子邮件地址。
我随附的代码 无法发送!
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();
}
}
}
如果有简单的方法解决转发事件问题就好了。
Forward()
创建一个新项目,如 here.
所述
所以从那时起您将需要使用该新项目:
var newItem = mailItem.Forward();
newItem.Recipients.Add("to.alt@web.de");
newItem.Send();
尝试使用 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
我想转发我的 Outlook 收件箱文件夹中的现有电子邮件。在最近的研究中,我发现了一些不同的解决方案:
- 获取当前邮件项目并将其复制到新邮件中
- 移动方法移动到不同的文件夹
- 转发方法...
我的目标是找到一种简单的方法将现有电子邮件转发到另一个 电子邮件地址。
我随附的代码 无法发送!
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();
}
}
}
如果有简单的方法解决转发事件问题就好了。
Forward()
创建一个新项目,如 here.
所以从那时起您将需要使用该新项目:
var newItem = mailItem.Forward();
newItem.Recipients.Add("to.alt@web.de");
newItem.Send();
尝试使用 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