C# - 如何在包含图像的电子邮件中包含 Outlook 签名? [英] C# - How to include Outlook signature in an email that contains images?

查看:28
本文介绍了C# - 如何在包含图像的电子邮件中包含 Outlook 签名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我在 Outlook 2013 中发送电子邮件的代码:

Here is my code to send the email in Outlook 2013:

public void GenerateEmail(OutEmail outEmail)
{
    var objOutlook = new Application();
    var mailItem = (MailItem)(objOutlook.CreateItem(OlItemType.olMailItem));
    mailItem.To = outEmail.SendTo;
    mailItem.Subject = outEmail.Subject;

    mailItem.RTFBody = outEmail.Body + outEmail.Signature;
    mailItem.Attachments.Add(outEmail.Attachment);

    Outlook.Account account = objOutlook.Session.Accounts["mail@email.com"];
    mailItem.SendUsingAccount = account;
    mailItem.Send();
    Console.WriteLine("done");
}

现在,outEmail.Signature 包含 Outlook 签名的 HTML 字符串,位于:C:UsersSOAppDataRoamingMicrosoftSignatures除了包含图像之外,它还正确格式化签名.如何在图像中包含签名,以便我可以在 Outlook 中创建新签名并将其包含在电子邮件中,而无需最终用户编辑签名 HTML.我不介意以编程方式进行,但我需要确保它适用于所有可能添加的签名.

Now, outEmail.Signature contains the HTML of the Outlook signature as a string, found at: C:UsersSOAppDataRoamingMicrosoftSignatures It formats the signature correctly apart from including the images. How can I include the signature with images such that I can create a new signature in Outlook and can include it within the e-mail WITHOUT needing an end user to edit the signature HTML. I don't mind doing it programmatically but I would need to be sure that it would work for all signatures that could be potentially added.

可能的解决方案?在 HTML 中,找到 img 标记的实例并删除 {SignatureName}_FILES,然后附加 {SignatureName}_FILES 中的所有内容文件夹到电子邮件?

Possible solution? In the HTML, find instances of the img tag and remove the {SignatureName}_FILES and then attach everything inside the {SignatureName}_FILES folder to the email?

干杯.

推荐答案

试试下面提到的

mailItem.GetInspector.Activate();
var signature = mailItem.HTMLBody;
mailItem.HTMLBody = EmailBody + signature;

这篇关于C# - 如何在包含图像的电子邮件中包含 Outlook 签名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆