Show Buttons
Share On Facebook
Share On Twitter
Share On Google Plus
Share On Linkdin
Share On Reddit
Contact us
Hide Buttons

Excel-VBA : Send Mail with Embedded Image in message body From MS Outlook using Excel.

In pre­vi­ous arti­cles you have learned about Send a Sim­ple Mail From MS Out­look Using Excel and how to send Attach­ment With the Mail MS Out­look Using Excel. ( I rec­om­mend you first read these arti­cles to under­stand the basics if you are new to this)

In this tuto­r­ial you will learn how to add an image in the mail body or mes­sage and send it from Microsoft Outlook.

Ides is to attach the image in hid­den man­ner and later add it to using image name in the Html­Body.

See the Code.

Com­plete Code:

Sub sumit()
Dim mainWB As Workbook
Dim SendID
Dim CCID
Dim Subject
Dim Body
Dim olMail As MailItem

Set otlApp = CreateObject("Outlook.Application")
Set olMail = otlApp.CreateItem(olMailItem)
Set Doc = olMail.GetInspector.WordEditor
'Dim colAttach As Outlook.Attachments
Dim oAttach As Outlook.Attachment

Set mainWB = ActiveWorkbook

SendID = mainWB.Sheets("Mail").Range("B1").Value
CCID = mainWB.Sheets("Mail").Range("B2").Value
Subject = mainWB.Sheets("Mail").Range("B3").Value
Body = mainWB.Sheets("Mail").Range("B4").Value
With olMail
    .To = SendID
    If CCID <> "" Then
      .CC = CCID
    End If
    .Subject = Subject
    'add the image in hidden manner, position at 0 will make it hidden
    .Attachments.Add "C:\Users\Sumit Jain\Pictures\11\city.jpg", olByValue, 0

    'Now add it to the Html body using image name
    'change the src property to 'cid:your image filename'
    'it will be changed to the correct cid when its sent.
    .HTMLBody = .HTMLBody & "<br><B>Embedded Image:</B><br>" _
                & "<img src='cid:city.jpg'" & "width='500' height='200'><br>" _
                & "<br>Best Regards, <br>Sumit</font></span>"
    .Display
    .Send
End With

MsgBox ("you Mail has been sent to " & SendID)

End Sub

Send Mail with Embedded Image in message body-1

Send Mail with Embed­ded Image in mes­sage body-1

Send Mail with Embedded Image in message body-2

Send Mail with Embed­ded Image in mes­sage body-2

You may also like...

5 Responses

  1. John Gibbs says:

    Is there any way to align the image? I tried chang­ing it to:
    ””

    But this just breaks it and I get nothing.

  2. Glenn says:

    Wow.…love the way you coded this.…simple and man­age­able. Thank you very much for sharing.

  3. Jaime says:

    This works really well if you’re using Out­look and I’ve tried this but when I send the mes­sage to any­one not using Out­look on a com­puter (mobile device, gmail, etc), they receive it as a blank image with the cid show­ing. Any idea on how to make this avail­able through­out all e-mail services?

  4. Mateus says:

    That’s great! Many thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: