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

查看:153
本文介绍了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:\Users\SO\AppData\Roaming\Microsoft\Signatures除了包含图像之外,它还可以正确格式化签名.如何在图像中包含签名,以便可以在Outlook中创建新的签名并将其包含在电子邮件中,而无需最终用户编辑签名HTML.我不介意以编程方式进行此操作,但是我需要确保它适用于所有可能添加的签名.

Now, outEmail.Signature contains the HTML of the Outlook signature as a string, found at: C:\Users\SO\AppData\Roaming\Microsoft\Signatures 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天全站免登陆