如何使用C#将收到的邮件作为附件附加到新邮件

时间:2019-01-16 16:50:48

标签: c# asp.net email email-attachments

我有一个(Microsoft.Office.Interop.Outlook.MailItem mail)邮件对象。
我希望此邮件作为附件附加到另一封邮件。
但找不到任何解决方案。任何人都可以提供帮助。

我创建了另一个邮件对象,如下所示: Microsoft.Office.Interop.Outlook.MailItem toSendMail = this.Application.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);

2 个答案:

答案 0 :(得分:0)

获取邮件,该邮件应作为附件添加。 然后调用«SaveAs({filename},Microsoft.Office.Interop.Outlook.OlSaveAsType.olMSG)»并将此文件添加到您的新邮件中

答案 1 :(得分:0)

根据您的要求,您希望将现有邮件对象作为附件发送到Outlook中的另一封邮件。

一种方法是通过将现有mailItem作为附件保存为其他附件。试试这个:

private void AddMessageAsAttachment(Microsoft.Office.Interop.Outlook.MailItem 
                     mailContainer,Microsoft.Office.Interop.Outlook.MailItem mailToAttach)
        {
            Microsoft.Office.Interop.Outlook.Attachments attachments = null;
            Microsoft.Office.Interop.Outlook.Attachment attachment = null;
            try
            {
                attachments = mailContainer.Attachments;
                attachment = attachments.Add(mailToAttach,
                   Microsoft.Office.Interop.Outlook.OlAttachmentType.olEmbeddeditem, 1, "The attached e-mail");
                mailContainer.Save();
            }
            catch (Exception ex)
            {
                    Console.WriteLine(ex.Message);
            }
            finally
            {
                if (attachment != null) Marshal.ReleaseComObject(attachment);
                if (attachments != null) Marshal.ReleaseComObject(attachments);
            }
        }

引用:https://www.add-in-express.com/creating-addins-blog/2011/08/12/how-to-add-existing-e-mail-message-as-attachment/