【问题标题】:How to attach a received mail as an attachment to a new mail using c#如何使用 c# 将收到的邮件作为附件附加到新邮件
【发布时间】:2019-06-10 19:34:16
【问题描述】:

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

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

【问题讨论】:

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


    【解决方案1】:

    根据您的要求,您希望将现有邮件对象作为附件发送到 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/

    【讨论】:

    • 不要写出只包含链接的答案。尝试另外总结最相关的信息。
    • @StefanG 我已经用相关代码编辑了答案,以便更好地参考和参考来源。
    【解决方案2】:

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

    【讨论】:

    • 有没有不使用saveas mail的直接方法。
    • 我认为 Outlook 互操作库不可能。创建一个临时文件,附加它,发送邮件,删除文件
    猜你喜欢
    • 1970-01-01
    • 2019-06-05
    • 2012-05-28
    • 1970-01-01
    • 1970-01-01
    • 2015-04-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多