Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
266 views
in Technique[技术] by (71.8m points)

excel - Sending embedded image in e-mail without using HTML code

I've been developing a code in VBA to treat a worksheet on Excel and send the result to my customer via e-mail, attaching the document and an image in the body of e-mail.

A part of this code, uses a HTML code to attach the image.

When I send this automatic e-mail to my customer, the image is blocked by a default protection of Outlook, that don't permit automatic download of HTML images.
enter image description here

The below is an example of my code, wherein myMail.HTMLBody is where I add the directory of image and the problem happens.
I can send the image to my customer via e-mail without block when I see the e-mail (in myMail.Display True), where I do the manual process in MS Outlook, clicking in Insert > Pictures and choose the image (this process that I want in my code).

How can I write this process (choose the image manually in Pictures) in my code?

I could request my customer define my e-mail as trusted or request them to uncheck this protection in Trust Center of MS Outlook, but I want to solve this problem from my side and not pass it to my customer.

Function Send_Email(EmailTO, EmailCC)
    
    Dim outlookApp As Outlook.Application
    Dim myMail As Outlook.MailItem
    Dim Source_File As String
    
    Set outlookApp = New Outlook.Application
    Set myMail = outlookApp.CreateItem(olMailItem)
    
    myMail.To = EmailTO
    myMail.CC = EmailCC
    myMail.Subject = "Subject
    myMail.HTMLBody = "<p><img src=""C:picturesimage.png"" alt="""" /></p>        
    myMail.Attachments.Add "C:picturesimage.png"
    myMail.Attachments.Add "C:documentsdocument.xlsx"
    myMail.Display True 'comment this out if you don't want to display email
    myMail.Send 'comment this out if you don't want to send yet
    
End Function
question from:https://stackoverflow.com/questions/65939271/sending-embedded-image-in-e-mail-without-using-html-code

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...