How to add image into email?

kyameizero

New Member
Joined
Jan 2, 2020
Messages
19
Office Version
  1. 365
Platform
  1. Windows
Hi,

How do I add an image to my email? I don't want the picture to be an attachment. It's like a company email, with the company logo shown in the email.
Is it possible to do that?

Please help!!

VBA Code:
Set xOutMail = xOutApp.CreateItem(0)
            xMailBody = "Dear " & xRgNameVal & " (EP number: " & xRgEPNoVal & "), " & vbNewLine & vbNewLine & _
                   "Your " & xRgQualVal & " licence is expiring on " & xRgDateVal & ". " & vbNewLine & vbNewLine & _
                   "To continue performing your " & xRgQualVal & " duties after the expiration date, " & _
                   "please renew your licence by completing the " & xRgQualVal & " re-certification course." & _
                   " You may approach your Training Coordinator to register for the course. " & vbNewLine & vbNewLine & _
                   "Thank you."
            xMailSubject = "Your " & xRgQualVal & " licence is expiring soon!"
              
        On Error Resume Next
            With xOutMail
                .To = xRgSendVal
                .CC = ""
                .BCC = ""
                .Subject = xMailSubject
                .Body = xMailBody
                .Display
            End With
        On Error GoTo 0
        Set xOutMail = Nothing
        Set xOutApp = Nothing
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
You can achieve this by using .HTMLBody rather than .Body
VBA Code:
            With xOutMail
                .To = xRgSendVal
                .CC = ""
                .BCC = ""
                .Subject = xMailSubject
                .Attachments.Add Source:="{path and filename}"
                .HTMLBody = xMailBody &  _
                "<img src='{filename}'" _
                & "width={width in px} height={height in px}>"
                .Display
            End With
You will also need to change xMailBody to HTML, so using <p>Text</p> or perhaps <br/> depending on the layout you're after.
 
Upvote 0
You can achieve this by using .HTMLBody rather than .Body
VBA Code:
            With xOutMail
                .To = xRgSendVal
                .CC = ""
                .BCC = ""
                .Subject = xMailSubject
                .Attachments.Add Source:="{path and filename}"
                .HTMLBody = xMailBody &  _
                "<img src='{filename}'" _
                & "width={width in px} height={height in px}>"
                .Display
            End With
You will also need to change xMailBody to HTML, so using <p>Text</p> or perhaps <br/> depending on the layout you're after.
Thanks for trying to help me!!

I first tried to change my xMailBody to HTML. However, I was given a Syntax Error. May I know what did I do wrong? I feel like the '=' sign is wrong.

VBA Code:
xMailBody = <p>Dear </p> & xRgNameVal & <p> (EP number: </p> & xRgEPNoVal & <p>), </p> & <br/> & <br/> & _
                   <p> Your </p> & xRgQualVal & <p> licence is expiring on </p> & xRgDateVal & <p>. </p> & <br/> & <br/> & _
                   <p>To continue performing your </p> & xRgQualVal & <p> duties after the expiration date, </p> & _
                   <p>please renew your licence by completing the </p> & xRgQualVal & <p> re-certification course.</p> & _
                   <p> You may approach your Training Coordinator to register for the course. </p> & <br/> & <br/> & _
                   <p>Thank you.</p>
 
Upvote 0
Thanks for trying to help me!!

I first tried to change my xMailBody to HTML. However, I was given a Syntax Error. May I know what did I do wrong? I feel like the '=' sign is wrong.

VBA Code:
xMailBody = <p>Dear </p> & xRgNameVal & <p> (EP number: </p> & xRgEPNoVal & <p>), </p> & <br/> & <br/> & _
                   <p> Your </p> & xRgQualVal & <p> licence is expiring on </p> & xRgDateVal & <p>. </p> & <br/> & <br/> & _
                   <p>To continue performing your </p> & xRgQualVal & <p> duties after the expiration date, </p> & _
                   <p>please renew your licence by completing the </p> & xRgQualVal & <p> re-certification course.</p> & _
                   <p> You may approach your Training Coordinator to register for the course. </p> & <br/> & <br/> & _
                   <p>Thank you.</p>
Please ignore my replied comment. I solved the problem. It is simply the <p> and <br> that I used lol.
 
Upvote 0
You can achieve this by using .HTMLBody rather than .Body
VBA Code:
            With xOutMail
                .To = xRgSendVal
                .CC = ""
                .BCC = ""
                .Subject = xMailSubject
                .Attachments.Add Source:="{path and filename}"
                .HTMLBody = xMailBody &  _
                "<img src='{filename}'" _
                & "width={width in px} height={height in px}>"
                .Display
            End With
You will also need to change xMailBody to HTML, so using <p>Text</p> or perhaps <br/> depending on the layout you're after.
I have converted my email body to HTML as intended. I tried using your example. However, the email shows "Error. Filename not specified." I named my file as "logo" and placed it in my c drive first for testing purposes. Please help.
VBA Code:
 On Error Resume Next
            With xOutMail
                .To = xRgSendVal
                .CC = ""
                .BCC = ""
                .Subject = xMailSubject
                .Attachments.Add Source:="C:/logo"
                .HTMLBody = xMailBody & _
                "<img src=""logo" _
                & "width=750  height=520>"
                .Display
            End With
 
Upvote 0
C:/logo will not work. Your file, even if named without an extension (not recommended) must be logo. (i.e. with the dot). Your file will normally be a common file type, so .jpg, .gif, etc. Further, you have typed double quotes around logo, when it should be single. I expect, presuming it is a .jpg, this will work:
.Attachments.Add Source:="C:/logo.jpg"
.HTMLBody = xMailBody & _
"<img src='logo.jpg'" _
& "width=750 height=520>"
 
Upvote 0
Ah I seee. Yes its in jpg, thank you very much. I've corrected my error :D

However, the email did not show my logo. Although, when I click the part the image supposed to come out, it is selected. This means that the image is there, but not shown. Is this the image's problem? i tried using other jpg images but it is the same. and also, does png work?
 
Upvote 0
And, yes, .png should be fine (I tried with one myself just now)
 
Upvote 0
Oh yeah we didnt realized the / is wrong LOL. However, I changed it and it still didn't work. I even tried to shift the image to another folder.
sadface

VBA Code:
On Error Resume Next
            With xOutMail
                .To = xRgSendVal
                .CC = ""
                .BCC = ""
                .Subject = xMailSubject
                .Attachments.Add Source:="C:\Users\17047382\Pictures\logo.png"
                .HTMLBody = xMailBody & _
                "<img src='logo.png'" _
                & "width=230 height=130>"
                .Display
            End With
        On Error GoTo 0
        Set xOutMail = Nothing
        Set xOutApp = Nothing
 
Upvote 0

Forum statistics

Threads
1,214,657
Messages
6,120,771
Members
448,991
Latest member
Hanakoro

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