Sending Emails with Signature

mikeymay

Well-known Member
Joined
Jan 17, 2006
Messages
1,600
Office Version
  1. 365
Platform
  1. Windows
I have been doing some testing but I'm still struggling to send an email that achieves the following
  • Adds the email body to the email to include
    • Carriage returns as per the defined range holding the body text
    • Show the hyperlinks in the defined body text as website addresses e.g. Fourth of July 2022
  • Includes the default signature showing the images within the signature, e.g. business logo, FaceBook icon with the associated hyperlink, etc

To date where I can achieve the signature images by using
VBA Code:
.Display
straight after the email is created
1656931128137.png


but then when I then add the email body text by using
VBA Code:
.Body = Range("EmailBody") & "<br>" & .Body
the signature is changed to what looks like plain text
1656937045639.png




Is there a way to retain the signature as the defined defined and the body text to show as defined.


TIA
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Give the below a try:
VBA Code:
Sub test()
    Dim OApp As Object, OMail As Object, signature As String
    
    Set OApp = CreateObject("Outlook.Application")
    
    Set OMail = OApp.CreateItem(0)
    With OMail
        .Display
        DoEvents
    End With
    signature = OMail.HTMLBody
    With OMail
        .to = "jbloggs@somebusiness.com"
        .Subject = "Subject here"
        .HTMLBody = "Body text here" & vbNewLine & signature
        .Send
    End With

    Set OMail = Nothing
    Set OApp = Nothing
End Sub
 
Upvote 0
Not quite there...

The email body text is not showing the carriage returns.

The email body is some defined text

E.g.
Hi David,

I hope you're keeping well.

Your policy with XXX is due for renewal on blah, blah, blah.

Another paragraph.

Another paragraph

When this is sent in the email it displays as
Hi David, I hope you're keeping well. Your policy with XXX is due for renewal on blah, blah, blah. Another paragraph. Another paragraph

The signature is correct and as required but the body needs to show as the example.


Thanks
 
Upvote 0
You will need to format your own HTML text - something like below:
VBA Code:
Sub test()
    Dim OApp As Object, OMail As Object, signature
    Dim strbody As String
    
    Set OApp = CreateObject("Outlook.Application")
    
    strbody = "<strong><p style=""font-size:20px"">Hi David," & "<br>" & "<br>" & _
            "I hope you're keeping well." & "<br>" & "<br>" & _
            "Your policy with XXX is due for renewal on blah, blah, blah." & "<br>" & "<br>" & _
            "Another paragraph." & "<br>" & "<br>" & _
            "etc...</p>"

    Set OMail = OApp.CreateItem(0)
    With OMail
        .display
        DoEvents
    End With
    signature = OMail.HTMLBody
    With OMail
        .to = "jbloggs@somebusiness.com"
        .Subject = "Subject here"
        .HTMLBody = strbody & signature
        .Send
    End With

    Set OMail = Nothing
    Set OApp = Nothing
End Sub
 
Upvote 0
Solution
Almost!

The text is now in the correct format using
VBA Code:
strBody = Replace(strBody, Chr(10), "<br>")
but the text for the hyperlinks is just text and not hyperlinked.
 
Upvote 0
Sorry, I only looked at the email when displayed and not sent.....

This now works!!!

Many thanks Georgiboy!
 
Upvote 0

Forum statistics

Threads
1,215,028
Messages
6,122,753
Members
449,094
Latest member
dsharae57

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top