How to add a signature the the body of email using VB.Net

Jeff Stiegler 466 Reputation points
2022-12-23T17:34:42.993+00:00

How do we add a signature to the the body of an email created in VB.Net? Want to use the signature that is specified in Outlook under Message | Signature.

This is the code we are using.

Private Sub btnEmail_Click(sender As Object, e As EventArgs) Handles btnEmail.Click  
  
        Dim EmailAddress = GetEmailAdress("RF", FPMain.txtFAcct2.Text)  
  
        Dim Outlook As Outlook.Application  
        Dim Mail As Outlook.MailItem  
        Dim Acc As Outlook.Account  
  
        Outlook = New Outlook.Application()  
        Mail = Outlook.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem)  
        Mail.To = EmailAddress  
        Mail.Subject = "Compliance Requirements"  
  
        For Each Acc In Outlook.Session.Accounts  
            'Select Case CaseCaseCasefirst pop3 For instance.  
            If Acc.AccountType = Microsoft.Office.Interop.Outlook.OlAccountType.olPop3 Then  
                Mail.Sender = Acc  
            End If  
        Next  
  
        'Attach files  
        Dim AttachmentDoc = GetDocPath() & "temp\" & FPMain.txtFAcct2.Text & ".pdf"  
  
        Mail.Attachments.Add(AttachmentDoc)  
  
        'Append some text:  
        Mail.HTMLBody &= "Please complete these compliance items or a giant green troll will eat you."  
  
  
        Mail.Display()  
  
    End Sub  
Developer technologies | VB
0 comments No comments
{count} votes

Answer accepted by question author
  1. Michael Taylor 61,176 Reputation points
    2022-12-23T18:29:13.217+00:00

    If you just want the default signature then a trick that used to work (see here) is to call GetInspector. This causes the HTML body to be rendered and therefore HTMLBody has the signature already injected into it. You don't need to do anything else. I heard a rumor it doesn't work with newer Office 365 accounts though.

    An alternative mentioned in the link is to create a new email as normal. The HtmlBody already has the signature in it. This would line up with how the UI works. The signature is simply appended to the end of the body automatically.

    If you need to get a specific signature then the link here provides example code on how to get the signatures. Note that MS adjusted signatures to allow syncing to the cloud. I don't know if that would impact this approach.

    2 people found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.