Embedded Inline Image Issue

tjiddy89

New Member
Joined
Mar 7, 2018
Messages
20
Hello all! Trying to generate an automated email with Gmail that includes a screenshot of a previously generated image but it's only showing the alternate text as defined in .HTMLbody. I've confirmed the HTML code works in a localized file but it's not showing in the email. Any help would be greatly appreciated!

Code:
 Enter your GMail credentials here and whoever you would like to send this report to.
    email = ""
    pass = ""
    msgTO = email
    msgCC = ""
    msgBCC = ""
    
    ' Had to remove the <> to avoid the actual document being counted as a live HTML tag.
    body = "img src='C:\Users\john.doe\Exports\agentDev.png' alt='Agent Development Chart'"
    
    Set NewMail = CreateObject("CDO.Message")
    Set mailConfig = CreateObject("CDO.Configuration")
    
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    ActiveWorkbook.Sheets.Copy
    ActiveWorkbook.Worksheets(1).Shapes("send").Delete
    ActiveWorkbook.Worksheets(1).Shapes("update").Delete
    ActiveWorkbook.Worksheets(1).Shapes("close").Delete
    ActiveWorkbook.SaveAs Filename:="agent.xlsx", FileFormat:=51
    ActiveWorkbook.Close
    Application.DisplayAlerts = True
    Application.ScreenUpdating = True
    
    mailConfig.Load -1
    Set fields = mailConfig.fields
    
    With NewMail
        .Subject = ""
        .From = email
        .To = msgTO
        .CC = msgCC
        .BCC = msgBCC
        .htmlbody = body
        .AddAttachment "agent.xlsx"
    End With
    
    msConfigURL = "http://schemas.microsoft.com/cdo/configuration"
    With fields
        .Item(msConfigURL & "/smtpusessl") = True
        .Item(msConfigURL & "/smtpauthenticate") = 1
        .Item(msConfigURL & "/smtpserver") = "smtp.gmail.com"
        .Item(msConfigURL & "/smtpserverport") = 465
        .Item(msConfigURL & "/sendusing") = 2
        .Item(msConfigURL & "/sendusername") = email
        .Item(msConfigURL & "/sendpassword") = pass
        .update
    End With
    NewMail.Configuration = mailConfig
    NewMail.Send
    Kill "agent.xlsx"
 
Last edited:

Some videos you may like

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.

tjiddy89

New Member
Joined
Mar 7, 2018
Messages
20
I've also tried the below code to no success.
Code:
img src='cid:agentDev.png'" & "width='100%'...

Full-disclosure: No idea what cid does, and I could not find any explanation online either.
 

tjiddy89

New Member
Joined
Mar 7, 2018
Messages
20
BUMP

To reword this, how can I insert inline images into emails via Gmail? I've been trying to figure this out myself for two days and it's driving me nuts lol
 

Watch MrExcel Video

Forum statistics

Threads
1,108,585
Messages
5,523,728
Members
409,532
Latest member
Lmfacc

This Week's Hot Topics

Top