'C# - How to include Outlook signature in an email that contains images?

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["[email protected]"];
    mailItem.SendUsingAccount = account;
    mailItem.Send();
    Console.WriteLine("done");
}

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.

EDIT: 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?

Cheers.



Solution 1:[1]

try below mentioned

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

Solution 2:[2]

Outlook inserts the signature when you call MailItem.Display or access MailItem.GetInspector (you do not have to do anything with the returned object).

If you want to programmatically insert a signature, Redemption (I am its author) exposes RDOSignature object which implements ApplyTo method.

UPDATE: as of the latest (Summer 2017) builds of Outlook, GetInspector trick no longer works. Now only MailItem.Display adds the signature to an unmodified message.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 user2538359
Solution 2