Add signature to Email body (1 Viewer)

Nous1970

New member
Local time
Today, 20:46
Joined
Feb 18, 2018
Messages
21
The email signature is the signature from outlook.
In the sample code from arnelgp it uses the standard outlook signatures. And in the second file it even shows it in a display.
All works fine except that when the email opens it doesn't display the image. Also when it is send the picture is not there.
It does show in the preview display in access. It just somehow does not let me display it in Outlook.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 11:46
Joined
Oct 29, 2018
Messages
21,454
Sorry, I am totally lost. We seem to be going in circles. I didn't look at the sample db, and I can't see yours.
The email signature is the signature from outlook.
This I understand.
In the sample code from arnelgp it uses the standard outlook signatures.
So far so good...
All works fine except that when the email opens it doesn't display the image.
This is where I get lost. Where did that reference to an "image" come from? Did Arnel use an image as a signature? If not, did you? Are you saying his sample works except when you use an image in your Outlook signature? Did you modify his code?
It does show in the preview display in access. It just somehow does not let me display it in Outlook.
Are you saying his code displays a Form in Access that shows the signature? Or are you saying Access opens Outlook and displays the signature correctly, but it disappears when you send the message, because you don't see it when you open the email in Outlook?

Perhaps it might also help us understand what's going on if you could post some screenshots.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 13:46
Joined
Feb 28, 2001
Messages
27,146
I just want to confuse and clarify at the same time. Remember that there is also such a thing as a digital signature; essentially, a hash if your digital certificate, and you can sign an Outlook document with your digital (security) signature as well. You have to do a few gyrations to "reveal" the correct command button (for the Outlook application) to use for this purpose, in the same way that you can send an encrypted e-mail - again having to do a trick or two to reveal the correct command button.

The "signature" is not part of the formal protocol of SMTP. I.e. there is a .To, .CC, .BCC, .Subject, .From, .Body, etc.... but no .Signature component. It is an addendum / insert / concatenation to the .Body portion whether using text or HTML for the body type.
 

Nous1970

New member
Local time
Today, 20:46
Joined
Feb 18, 2018
Messages
21
I just want to confuse and clarify at the same time. Remember that there is also such a thing as a digital signature; essentially, a hash if your digital certificate, and you can sign an Outlook document with your digital (security) signature as well. You have to do a few gyrations to "reveal" the correct command button (for the Outlook application) to use for this purpose, in the same way that you can send an encrypted e-mail - again having to do a trick or two to reveal the correct command button.

The "signature" is not part of the formal protocol of SMTP. I.e. there is a .To, .CC, .BCC, .Subject, .From, .Body, etc.... but no .Signature component. It is an addendum / insert / concatenation to the .Body portion whether using text or HTML for the body type.
Hello @The_Doc_Man

Thank you for the clarification

THis is not so much about the digital signature.

I just want to add the outlook signature to the end of the mail when I send it to Outlook.
And this works fine except it is not displaying the signature.

I assume it is a safety future, but I wish I could bypass it.

Below is the code I found online, which works really well... except the picture :-(


Code:
Sub Mail_Outlook_With_Signature_Html_2()
' Don't forget to copy the function GetBoiler in the module.
' Working in Office 2000-2016
    Dim OutApp As Object
    Dim OutMail As Object
    Dim strbody As String
    Dim SigString As String
    Dim Signature As String

    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)

    strbody = "<H3><B>Dear Customer Ron de Bruin</B></H3>" & _
              "Please visit this website to download the new version.<br>" & _
              "Let me know if you have problems.<br>" & _
              "<A HREF=""http://www.rondebruin.nl/tips.htm"">Ron's Excel Page</A>" & _
              "<br><br><B>Thank you</B>"

    'Change only Mysig.htm to the name of your signature
    SigString = Environ("appdata") & _
                "\Microsoft\Signatures\Mysig.htm"

    If Dir(SigString) <> "" Then
        Signature = GetBoiler(SigString)
    Else
        Signature = ""
    End If

    On Error Resume Next

    With OutMail
        .To = "ron@debruin.nl"
        .CC = ""
        .BCC = ""
        .Subject = "This is the Subject line"
        .HTMLBody = strbody & "<br>" & Signature
        .Send    'or use .Display
    End With

    On Error GoTo 0
    Set OutMail = Nothing
    Set OutApp = Nothing
End Sub


Function GetBoiler(ByVal sFile As String) As String
'Dick Kusleika
    Dim fso As Object
    Dim ts As Object
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set ts = fso.GetFile(sFile).OpenAsTextStream(1, -2)
    GetBoiler = ts.readall
    ts.Close
End Function
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 02:46
Joined
May 7, 2009
Messages
19,229
change your code to this:
Code:
Sub Mail_Outlook_With_Signature_Html_2()
' Don't forget to copy the function GetBoiler in the module.
' Working in Office 2000-2016
    Dim OutApp As Object
    Dim OutMail As Object
    Dim strbody As String
    Dim SigString As String
    Dim Signature As String

    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)

    strbody = "<H3><B>Dear Customer Ron de Bruin</B></H3>" & _
              "Please visit this website to download the new version.<br>" & _
              "Let me know if you have problems.<br>" & _
              "<A HREF=""http://www.rondebruin.nl/tips.htm"">Ron's Excel Page</A>" & _
              "<br><br><B>Thank you</B>"

    'Change only Mysig.htm to the name of your signature
    SigString = "Mysig.htm"

    If Dir(SigString) <> "" Then
        Signature = ReadSignature(SigString)
    Else
        Signature = ""
    End If

    On Error Resume Next

    With OutMail
        .To = "ron@debruin.nl"
        .CC = ""
        .BCC = ""
        .Subject = "This is the Subject line"
        .HTMLBody = strbody & "<br>" & Signature
        .Send    'or use .Display
    End With

    On Error GoTo 0
    Set OutMail = Nothing
    Set OutApp = Nothing
End Sub


Private Function ReadSignature(sigName As String) As String
' arnelgp
'
' sigName should include the .htm extension
'
    Dim appDataDir  As String
    Dim sig         As String
    Dim sigPath     As String
    Dim fileName    As String
    appDataDir = Environ$("APPDATA") & "\Microsoft\Signatures"
    sigPath = appDataDir & "\" & sigName
    With CreateObject("Scripting.FileSystemObject")
        sig = .OpenTextFile(sigPath).ReadAll
    End With
    ' fix relative references to images, etc. in sig
    ' by making them absolute paths, OL will find the image
    fileName = Replace$(sigName, ".htm", "_files/")
    sig = Replace$(sig, fileName, appDataDir & "\" & fileName)
    ReadSignature = sig
End Function
 

Nous1970

New member
Local time
Today, 20:46
Joined
Feb 18, 2018
Messages
21
Hello Arnelgp

Thank you for this code.
I tried this already with the same result

I do have a question about your code.

Code:
 'Change only Mysig.htm to the name of your signature
    SigString = "Mysig.htm"

    If Dir(SigString) <> "" Then

If you place only the name it will not find the "Dir", or am I missing something here?

Below is how it is displayed in the email.
1690257915679.png
 

Attachments

  • 1690257952953.png
    1690257952953.png
    17.8 KB · Views: 40

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 02:46
Joined
May 7, 2009
Messages
19,229
ok change the code i gave with this one:
Code:
Sub Mail_Outlook_With_Signature_Html_2()
' Don't forget to copy the function GetBoiler in the module.
' Working in Office 2000-2016
    Dim OutApp As Object
    Dim OutMail As Object
    Dim strbody As String
    Dim SigString As String
    Dim Signature As String

    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)

    strbody = "<H3><B>Dear Customer Ron de Bruin</B></H3>" & _
              "Please visit this website to download the new version.<br>" & _
              "Let me know if you have problems.<br>" & _
              "<A HREF=""http://www.rondebruin.nl/tips.htm"">Ron's Excel Page</A>" & _
              "<br><br><B>Thank you</B>"

    'Change only Mysig.htm to the name of your signature
    SigString = "Mysig.htm"


    Signature = ReadSignature(SigString)

    On Error Resume Next

    With OutMail
        .To = "ron@debruin.nl"
        .CC = ""
        .BCC = ""
        .Subject = "This is the Subject line"
        .HTMLBody = strbody & "<br>" & Signature
        .Send    'or use .Display
    End With

    On Error GoTo 0
    Set OutMail = Nothing
    Set OutApp = Nothing
End Sub


Private Function ReadSignature(sigName As String) As String
' arnelgp
'
' sigName should include the .htm extension
'
    Dim appDataDir  As String
    Dim sig         As String
    Dim sigPath     As String
    Dim fileName    As String
    appDataDir = Environ$("APPDATA") & "\Microsoft\Signatures"
    sigPath = appDataDir & "\" & sigName
    If Len(Dir$(sigPath)) = 0 Then Exit Function
    With CreateObject("Scripting.FileSystemObject")
        sig = .OpenTextFile(sigPath).ReadAll
    End With
    ' fix relative references to images, etc. in sig
    ' by making them absolute paths, OL will find the image
    fileName = Replace$(sigName, ".htm", "_files/")
    sig = Replace$(sig, fileName, appDataDir & "\" & fileName)
    ReadSignature = sig
End Function
 

Nous1970

New member
Local time
Today, 20:46
Joined
Feb 18, 2018
Messages
21
ok change the code i gave with this one:
Code:
Sub Mail_Outlook_With_Signature_Html_2()
' Don't forget to copy the function GetBoiler in the module.
' Working in Office 2000-2016
    Dim OutApp As Object
    Dim OutMail As Object
    Dim strbody As String
    Dim SigString As String
    Dim Signature As String

    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)

    strbody = "<H3><B>Dear Customer Ron de Bruin</B></H3>" & _
              "Please visit this website to download the new version.<br>" & _
              "Let me know if you have problems.<br>" & _
              "<A HREF=""http://www.rondebruin.nl/tips.htm"">Ron's Excel Page</A>" & _
              "<br><br><B>Thank you</B>"

    'Change only Mysig.htm to the name of your signature
    SigString = "Mysig.htm"


    Signature = ReadSignature(SigString)

    On Error Resume Next

    With OutMail
        .To = "ron@debruin.nl"
        .CC = ""
        .BCC = ""
        .Subject = "This is the Subject line"
        .HTMLBody = strbody & "<br>" & Signature
        .Send    'or use .Display
    End With

    On Error GoTo 0
    Set OutMail = Nothing
    Set OutApp = Nothing
End Sub


Private Function ReadSignature(sigName As String) As String
' arnelgp
'
' sigName should include the .htm extension
'
    Dim appDataDir  As String
    Dim sig         As String
    Dim sigPath     As String
    Dim fileName    As String
    appDataDir = Environ$("APPDATA") & "\Microsoft\Signatures"
    sigPath = appDataDir & "\" & sigName
    If Len(Dir$(sigPath)) = 0 Then Exit Function
    With CreateObject("Scripting.FileSystemObject")
        sig = .OpenTextFile(sigPath).ReadAll
    End With
    ' fix relative references to images, etc. in sig
    ' by making them absolute paths, OL will find the image
    fileName = Replace$(sigName, ".htm", "_files/")
    sig = Replace$(sig, fileName, appDataDir & "\" & fileName)
    ReadSignature = sig
End Function

Still same issue of not able to display picture.
I have a feeling it is an outlook security issue.
Just can't figure it out.

Thanks for the help though, it is much appreciated..
 
Last edited:

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 02:46
Joined
May 7, 2009
Messages
19,229
i am sorry that it does not work for you.
i made a short video of what i have (working in me, with same Code i uploaded).

the Signature is a jpg image.
 

Nous1970

New member
Local time
Today, 20:46
Joined
Feb 18, 2018
Messages
21
i am sorry that it does not work for you.
i made a short video of what i have (working in me, with same Code i uploaded).

the Signature is a jpg image.
I created a whole new module again, still no luck.
Again, I think it is something in outlook.

Thank you again.
 

Minty

AWF VIP
Local time
Today, 19:46
Joined
Jul 26, 2013
Messages
10,368
Did you try the method in the code I presented at the beginning of the thread?
As far as I'm aware it works.
 

Nous1970

New member
Local time
Today, 20:46
Joined
Feb 18, 2018
Messages
21
Did you try the method in the code I presented at the beginning of the thread?
As far as I'm aware it works.
Well whattayouknow.... I totaly missed that one.
That one works indeed.

Nice workaround

It only does not pick up on the .SentOnBehalfOfName

Any ideas?
 

Minty

AWF VIP
Local time
Today, 19:46
Joined
Jul 26, 2013
Messages
10,368
I've always had issues .SentOnBehalfOf
You basically can't use it by simply inserting another email address, you have to refer to the account.

More detailed info here:
 

Gasman

Enthusiastic Amateur
Local time
Today, 19:46
Joined
Sep 21, 2011
Messages
14,237
This is how I determined which account to use.
On my phone right now, but
 

Users who are viewing this thread

Top Bottom