UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Adding An Image Into An Email Using VBA, Access 2016    
 
   
MisterChips
post Feb 10 2018, 11:39 AM
Post#1



Posts: 62
Joined: 29-January 17



I have searched this forum with "img src=" but cannot find the answer to my query, so I ask you if you can help me please.

I have built a working email using VBA and am trying to add a banner at the start of the BodyText.
have the following line of code.

BodyText = "<img src= http://www.website.co.UK/pwfh_masthead.jpg" & ">"
If I cut and paste the http line into my browser it returns the image that I am trying to include in my email.

the email arrives in my outlook inbox with all the other email content, but it doesn't include the image.
'debug.print BodyText' shows the following ..... <IMG src= http://www.website.co.UK/pwfh_masthead.jpg>

Where am I going wrong please?

Go to the top of the page
 
DanielPineault
post Feb 10 2018, 12:04 PM
Post#2


UtterAccess VIP
Posts: 6,072
Joined: 30-June 11



You need double quotes surrounding the URL, so try

CODE
BodyText = "<img src=""http://www.website.co.UK/pwfh_masthead.jpg"">"


It is also good to include the height and width attributes if they are know (or can be determined).
Go to the top of the page
 
MisterChips
post Feb 10 2018, 12:56 PM
Post#3



Posts: 62
Joined: 29-January 17



Many thanks Daniel

I changed the code as below:-
BodyText = "<img src=""http://www.website.co.UK/pwfh_masthead.jpg"">"
debug.print showed . . . . . <img src="http://www.website.co.UK/pwfh_masthead.jpg">
but the email did not show the image.

I also added the width and height, as follows:-
BodyText = "<img src=""http://www.website.co.UK/pwfh_masthead.jpg width=900 height=20"">"
debug.print showed . . . . . <img src="http://www.website.co.UK/pwfh_masthead.jpg width=900 height=20">
This did not work either

I also tried BodyText = "<img src=""http://www.website.co.UK/pwfh_masthead.jpg width='900' height='20'"">"
debug showed <img src="http://www.website.co.UK/pwfh_masthead.jpg width='900' height='20'">
but also with no luck.

Any further ideas please?


P.S. Whilst I don't think it has any bearing on my problem, I don't seem able to get rid of the following in my subject text
which shows up in my email subject line as follows.
<div>PWFH - Assistance required please.</div>
I have no idea whet the div's come from ... it is not in my code.

Go to the top of the page
 
DanielPineault
post Feb 10 2018, 12:58 PM
Post#4


UtterAccess VIP
Posts: 6,072
Joined: 30-June 11



I think you're going to have to show us your complete code for us to debug.

Also, the URL is invalid.
http://www.website.co.UK/pwfh_masthead.jpg -> gives an error page, not an image?

You need to surround each individual attribute with quotes (see: https://www.w3schools.com/tags/tag_img.asp )
CODE
<img src="http://www.website.co.UK/pwfh_masthead.jpg width=900 height=20">

needs to be
CODE
<img src="http://www.website.co.UK/pwfh_masthead.jpg" width="900" height="20">
Go to the top of the page
 
MisterChips
post Feb 10 2018, 01:07 PM
Post#5



Posts: 62
Joined: 29-January 17



Hi Daniel.

I substituted the word 'website' for my own domain name to preserve anonymity.
The URL does resolve the image, when used in my browser.

I will look towards including much of my code, where I can, and will get back to you.
Thank you for your time thus far.
Go to the top of the page
 
MisterChips
post Feb 10 2018, 01:24 PM
Post#6



Posts: 62
Joined: 29-January 17



Daniel,
I have included the bulk of my code which I hope will not 'muddy the water'.
This block of code is sitting inside a do while ... loop to deal with multiple email sending, all of which, other than not getting a masthead, works as required.
I have had to substitute the words 'website' and 'deleted' for some sensitive information, but otherwise it is as coded.
Many thanks.



SubjectText = Forms!f_body_text_override.Subject_Line_Override
BodyText = ""

If Check57 = -1 Then BodyText = BodyText & "<img src=""http://www.website.co.UK/pwfh_masthead.jpg width='900' height='20'"">"
Debug.Print BodyText
BodyText = "<br/>" & "<br/>" & SubjectText & "<br/>" & "<br/>"
BodyText = BodyText & "<br/>" & "Dear " & DLookup("Salutation", "t_secs") & " " & DLookup("forename", "t_secs") & "," & "<br/>" & "<br/>"
BodyText = BodyText & Forms!f_body_text_override.Body_Text_Override & "<br/>"
BodyText = BodyText & Forms!f_body_text_override.Signature_Line_Override
MessageType = "Free Text Email"
If Check28 = -1 Then MessageType = "FREE TEXT Test Message": TestEmail = Forms!f_variables.testemailaddress
DoCmd.OpenForm "f_message_text"
Forms!f_message_text.text0 = vbCrLf & "Email sent to " & vbCrLf & rs!Email & vbCrLf & rs!Name '
If Check28 = -1 Then Forms!f_message_text.text0 = vbCrLf & "Test FREE TEXT Email sent to " & vbCrLf & TestEmail

If Check28 = -1 Then Sleep 2000 Else Sleep 500
DoCmd.Close acForm, "f_message_text"
'End If
'End If

Set imsg = CreateObject("CDO.Message")
Set iconf = CreateObject("CDO.Configuration")
Set flds = iconf.Fields
'############################################################################
#### SEND TO
schema = "http://schemas.microsoft.com/CDO/configuration/"
flds.Item(schema & "sendusing") = cdoSendUsingPort
flds.Item(schema & "smtpserver") = "in-v3.mailjet.com"
flds.Item(schema & "smtpserverport") = 25
flds.Item(schema & "smtpauthenticate") = cdoBasic ' "Auth" 'cdoBasic
flds.Item(schema & "sendusername") = "deleted"
flds.Item(schema & "sendpassword") = "deleted"
flds.Item(schema & "smtpusessl") = 1 ' was 1
flds.Update

imsg.To = rs!Email ' rs!Email ' but if this is a test email see below Check165 CLEAR FOR TESTING
If Check28 = -1 Then imsg.To = "DaveTestFreeText@website.co.UK" '

imsg.From = "dave@website.co.UK" 'Text272
imsg.Subject = SubjectText

If CountCC = 0 Then imsg.CC = "website@icloud.com" & "," & "website@uwclub.net"
CountCC = CountCC + 1

'imsg.BCC = "SendBCC@websiteco.UK"

imsg.HTMLBody = BodyText
imsg.Sender = "dave@deleted.co.UK"
imsg.Organization = "deleted"
'If Forms!f_secs.Check21 = False Then imsg.AddAttachment "F:\DATA\asons\PWFH emailing\" & rs!Name & ".xlsx" ' only send out for list review emails
'If Check108 = -1 Then imsg.AddAttachment "C:\Attachment_files\" & Attach2: Text151 = "ATTACHMENT"
'If Check110 = -1 Then imsg.AddAttachment "C:\Attachment_files\" & Attach3: Text151 = "ATTACHMENT"
imsg.ReplyTo = "dave@deleted.co.UK" 'Text276
Set imsg.Configuration = iconf
imsg.Send
Go to the top of the page
 
MisterChips
post Feb 10 2018, 01:26 PM
Post#7



Posts: 62
Joined: 29-January 17




Perhaps I should try to find some other method of inserting this image!
Go to the top of the page
 
DanielPineault
post Feb 10 2018, 02:07 PM
Post#8


UtterAccess VIP
Posts: 6,072
Joined: 30-June 11



See if this doesn't work for you, https://groups.google.com/forum/#!topic...ipt/SusVShINK-Y




Also, your issue with the subject, the Forms!f_body_text_override.Subject_Line_Override control/field is it plain text or rtf?


Go to the top of the page
 
MisterChips
post Feb 10 2018, 03:10 PM
Post#9



Posts: 62
Joined: 29-January 17



I interpreted the link you kindly gave me as being <img src=cid:http://www.website.co.UK/pwfh_masthead.jpg>
which did not work for me ... and I don't understand what the CID: element is trying to do.

All the fields in the message are Rich Text formatted at the table design stage and this is also so in the form.

This post has been edited by MisterChips: Feb 10 2018, 03:25 PM
Go to the top of the page
 
DanielPineault
post Feb 10 2018, 04:19 PM
Post#10


UtterAccess VIP
Posts: 6,072
Joined: 30-June 11



Well, the Rich text probably explain why you are getting <div>...</div> in your subject. You could try http://www.devhut.net/2014/12/10/VBA-remov...-from-a-string/ to eliminate the div tag.
Go to the top of the page
 
MisterChips
post Feb 10 2018, 05:32 PM
Post#11



Posts: 62
Joined: 29-January 17



Daniel.
Spot on!
Plain text cleared up the problem. . . . Thank you.
The strange thing is that all the other Email fields work with Rich text!

I am still trying to find a 'work-around' for my pwfh_masthead.jpg problem ... but off to bed now.

Thanks for your help
Go to the top of the page
 
PhilS
post Feb 11 2018, 10:08 AM
Post#12



Posts: 500
Joined: 26-May 15
From: The middle of Germany


QUOTE
CODE
If Check57 = -1 Then BodyText = BodyText & "<img src=""http://www.website.co.UK/pwfh_masthead.jpg width='900' height='20'"">"
Debug.Print BodyText
BodyText = "<br/>" & "<br/>" & SubjectText & "<br/>" & "<br/>"

In this line you just overwrite the BodyText variable. So, when it is assigned to the actual email body text later, it does not contain your IMG-Tag at all anymore .
If you'd used Debug.Print to display the complete text immediately before it is added to the email you'd probably spotted that issue right away.

QUOTE
I interpreted the link you kindly gave me as being <img src=cid:http://www.website.co.UK/pwfh_masthead.jpg>
which did not work for me ... and I don't understand what the CID: element is trying to do.

The CID (Content ID) references an image added to an email as attachment.
I explained how to use this in my text on sending HTML-emails with Microsoft Access and Outlook. It does not apply to your scenario, but it still should explain the purposed and usage of the CID.
Go to the top of the page
 
MisterChips
post Feb 12 2018, 05:27 AM
Post#13



Posts: 62
Joined: 29-January 17



PhilS.

Thanks. Got it going now. Silly, basic, programming error!
I spent so much time thinking that the URL line was in error, i didn't look for the more obvious.
I am indebted to you.

I thank all of you who went out of your way to assist me.


Go to the top of the page
 
DanielPineault
post Feb 12 2018, 09:28 AM
Post#14


UtterAccess VIP
Posts: 6,072
Joined: 30-June 11



Glad to hear it's all sorted out now! thumbup.gif
Go to the top of the page
 


Custom Search
RSSSearch   Top   Lo-Fi    25th September 2018 - 04:32 PM