Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am using the Microsoft.Office.Interop.Outlook.Application to generate an email and display it on the screen before the user can send it. The application is a winform application coded in C# in the .NET Framework 3.5 SP1 and it is Microsoft Outlook 2003. I am using the following code:

public static void GenerateEmail(string emailTo, string ccTo, string subject, string body)
    {
        var objOutlook = new Application();
        var mailItem = (MailItem)(objOutlook.CreateItem(OlItemType.olMailItem));        
        mailItem.To = emailTo;          
        mailItem.CC = ccTo;
        mailItem.Subject = subject;
        mailItem.HTMLBody = body;
        mailItem.Display(mailItem);
    }

My question is:

How do i insert/add the default signature of the user who is using the application in the body of the email generated? Any help appreciated.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
789 views
Welcome To Ask or Share your Answers For Others

1 Answer

There is a really quick easy way that hasn't been mentioned. See modified below:

public static void GenerateEmail(string emailTo, string ccTo, string subject, string body)
{
    var objOutlook = new Application();
    var mailItem = (MailItem)(objOutlook.CreateItem(OlItemType.olMailItem));        
    mailItem.To = emailTo;          
    mailItem.CC = ccTo;
    mailItem.Subject = subject;
    mailItem.Display(mailItem);
    mailItem.HTMLBody = body + mailItem.HTMLBody;
}

By editing the HTMLBody after you display the mailitem you allow for Outlook to do the work of adding the default signature and then essentially copy, edit, and append.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...