Solved How to add a signature to a mail (1 Viewer)

KitaYama

Well-known member
Local time
Today, 18:11
Joined
Jan 6, 2022
Messages
1,541
This is a simplified version of a vbs script to create a mail

Code:
Sub createOutlookEmail()
    Dim appOutlook
    Set appOutlook = Wscript.CreateObject("Outlook.Application")
    Set objMail = appOutlook.CreateItem(0)

    With objMail
        .To="Some mail address"
        .CC="Some mail address"
        .BCC="Some mail address"
        .Subject="Test"
        .BodyFormat=2
        .Body="Some text"
        .Attachments.Add "Some file"
        .Display
    End With
 
    Set objMail = Nothing
    Set appOutlook = Nothing
End Sub

' Run the procedure
Call createOutlookEmail()

The code works perfect but the default signature is not added to the mail.
How can I add the default signature to the mail?

Thanks.
 
Last edited:

June7

AWF VIP
Local time
Today, 01:11
Joined
Mar 9, 2014
Messages
5,472
I think this requires use of HTML coding.
Either build an image file (png, bmp, jpg) that can be included at end of email or use default signature card. Example of the latter:
Code:
Sub Email()
Dim appOutLook As Outlook.Application
Dim MailOutLook As Outlook.MailItem
Dim body As String, rs As DAO.Recordset, strA As String
Set appOutLook = CreateObject("Outlook.Application")
Set rs = CurrentDb.OpenRecordset("SELECT UmpID, Email FROM Umpires WHERE UmpID = 1", dbOpenDynaset, dbSeeChanges)
DoCmd.OutputTo acOutputReport, "Compensation", acFormatPDF, "C:\Users\Owner\June\Forums\test.pdf"
Do While Not rs.EOF
    Set MailOutLook = appOutLook.CreateItem(olMailItem)
    With MailOutLook
        .BodyFormat = olFormatHTML
        .To = rs!Email
        ''.cc = ""
        ''.bcc = ""
        strA = "C:\Users\Owner\June\MyStuff\Exercises.docx"
        .Attachments.Add strA
        .Subject = "Test : "
        body = "<table style='text-align:right;border:1px solid black;font-family:calibri;border-collapse:collapse;padding:15px'><tr style='background:yellow;mso-highlight:yellow'>" & _
            "<th>No</th><th>Client</th><th>Date</th><th>PR</th><th>Currency</th><th>Amt</th></tr>" & _
            "<tr><td>12345</td><td>Jones</td><td>12Dec2017</td><td>ABC</td><td>US</td><td>2000</td></tr>" & _
            "<tr><td>67890</td><td>Finkbiner</td><td>12Dec2017</td><td>ABC</td><td>US</td><td>1000</td></tr></table>"
        body = "<HTML style='font-family:calibri'><Body><font face='calibri'><a href='C:\Users\Owner\June\Forums'><img SRC=C:\Users\Owner\June\DOT\Lab\Editing\LABDB.png></a><br>" & _
            "<font color='red' size='1'>&nbsp;&nbsp;&nbsp;&nbsp;READ THIS EMAIL COMPLETELY</font><br>" & _
            body & _
            "<br><b>Please confirm or I will kick you.</b><br>" & _
            "</font></Body></HTML>" & _
            "<table><tr bgcolor='yellow'>THIS WILL CREATE BLACK TEXT WITH YELLOW BACKGROUND</tr></table>" & _
            "<span style='background:yellow'>ALSO BLACK TEXT YELLOW BACKGROUND</span>"
        .Display
        'following allows including Outlook email signature, however, must Display before Send
        .HTMLBody = Replace(.HTMLBody, "<div class=WordSection1><p class=MsoNormal><o:p>", "<div class=WordSection1><p class=MsoNormal><o:p>" & body)
        ''.send
    End With
    'MsgBox "Continue"
    rs.MoveNext
Loop
I have tried other versions of code to use default signature but this is only one I can get to work.
 
Last edited:

KitaYama

Well-known member
Local time
Today, 18:11
Joined
Jan 6, 2022
Messages
1,541
Seems that @Minty has a simpler way.
He opens an empty mail, reads the signature as a string and starts over.

 

Minty

AWF VIP
Local time
Today, 10:11
Joined
Jul 26, 2013
Messages
10,371
I can't take the real credit for that I'm afraid.
I know I found it somewhere (no idea where, sorry to the originator) on the internet, tried it and it worked and was super simple.
 

KitaYama

Well-known member
Local time
Today, 18:11
Joined
Jan 6, 2022
Messages
1,541
I can't take the real credit for that I'm afraid.
I know I found it somewhere (no idea where, sorry to the originator) on the internet, tried it and it worked and was super simple.
I had to delete the following line. It brings up a window which needs a user confirmation and adds an additional step for user.
OutApp.Session.Logon

what does this line exactly do and when it’s necessary?
thanks
 

Minty

AWF VIP
Local time
Today, 10:11
Joined
Jul 26, 2013
Messages
10,371
That's a good question, I think it's a hangover from a much older version of office.

From memory if Outlook wasn't loaded it would load and effectively ask you for an account to use, rather than the current method which will just load the default profile.
 

KitaYama

Well-known member
Local time
Today, 18:11
Joined
Jan 6, 2022
Messages
1,541
That's a good question, I think it's a hangover from a much older version of office.

From memory if Outlook wasn't loaded it would load and effectively ask you for an account to use, rather than the current method which will just load the default profile.
Thanks
 

Users who are viewing this thread

Top Bottom