B4J Question image in a html mail message

rbirago

Active Member
Licensed User
Longtime User
Using smtp mail is quite simple (jNet library), but I cannot send an html message containing an image.
I tried to send the html message by my mail agent (Thunderbird) and everything is ok.
Trying to send the same message by jNet the message is sent correctly, but at destination the image is not present.
The image is of course in an external server.
Searching the B4X forum I've found some threads about this problem and someone talked about a "NetExtra library" for this kind of problem, but I have not found this library.
Can someone help me?
thanks in advance
Roberto
 

DonManfred

Expert
Licensed User
Longtime User
This may of help.

Consider to put the Image(s) on your Webhosting and just link the url of this image in the img tags src attribute.
 
Upvote 0

rbirago

Active Member
Licensed User
Longtime User
Thanks for the quick replies...but:
1) My images ARE inside my webhosting area, but the html email (sent by my B4J app) arrived at destination doesn't show the image.
The same html message sent by Thunderbird shows the image.
2) My app is a B4J app, so I cannot use this NetExtras library.
other suggestions?
thanks
 
Upvote 0

rbirago

Active Member
Licensed User
Longtime User
here is my test project. You have to fill your specific fields for email service.
Using button SEND you send a plain text. Using button SEND HTML you send the file "objects/test1b.html".
You can try to send the same file by your mail client and you can see that the image is correctly sent.
thanks
Roberto
 

Attachments

  • test2.zip
    192.6 KB · Views: 213
Upvote 0

inakigarm

Well-Known Member
Licensed User
Longtime User
here is my test project

B4X:
    Dim smtp As SMTP
    smtp.Initialize("smtp.gmail.com", 587, "[email protected]", "--pass--", "Mailer")
    smtp.StartTLSMode = True
    smtp.UseSSL = True
    smtp.Sender = "<" & "[email protected]" & ">"
    smtp.To.Add("[email protected]")
    smtp.Subject = "Test"
    smtp.HtmlBody = True
    smtp.Body = File.ReadString(File.DirApp,"test1b.html")   
    smtp.Send
It Displays fine on Yahoo mail

1577648337005.png


But it doesn't display correctly on Gmail, you'll have to google which are the best format to send html body mails to Gmail https://stackoverflow.com/questions/21437916/html-image-not-showing-in-gmail

1577648043498.png
 
Upvote 0

rbirago

Active Member
Licensed User
Longtime User
Really I don't understand where is the trick, because I tried to send the imaged html to a lot of different destinations, like @gmail.com or @yahoo.com , etc, but always the html message sent by Thunderbird is ok and the same html message sent by B4J app doesn't show the image. I also followed Stackoverflow suggestions, but always without success.
What can I try?
 
Upvote 0

inakigarm

Well-Known Member
Licensed User
Longtime User
What can I try?
"this WORKS on Yahoo/Gmail" --> you'll have to compose the html mail following Gmail HTML syntax rules :
1) Add Free HTML Editor for Gmail extension on Chrome Browser
2) Write a new mail on Gmail and select Html Editor as mail Editor
1577959138207.png

3) Design the html mail:
1577959689114.png


4) Copy the Html Source and Paste it on html file (file test.html)
1577959749778.png


5) Send the mail from B4J

Html mail displays fine on Chrome browsers for Yahoo and Gmail mails
 
Upvote 0

rbirago

Active Member
Licensed User
Longtime User
I will try exactly what you suggest. I have some doubts, because in the trial by Thunderbird I have selected "insert HTML text" and I have copied in it the Html file text (copy&paste)...and all was ok. Anyway I will try your method. Thank you for now.
Roberto
 
Upvote 0

MicroDrie

Well-Known Member
Licensed User
The trouble for you is that Gmail has a tight security plan for security wise by Gmail seen as dangerous attachments. You can simple avoid this Gmail security issue by dropping the attachments. Insert the text only converted image file as a base64 text string at image insert point.

The HTML code to display an image::
<div>
    <p>Taken from wikpedia</p>
    <img src="data:image/png;base64, iVBORw0KGgoAAAANSUhEUgAAAAUA
AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO
    9TXL0Y4OHwAAAABJRU5ErkJggg==" alt="Red dot" />
</div>

The benefit for this solution is that every receiver of the email can see your image directly without the need to allow an (attached) images and replies also include the image view.
 
Upvote 0

rbirago

Active Member
Licensed User
Longtime User
Effectively I have just considered the way to embed the image in the html file (base64), but really I don't like too much this solution. First of all because building the html page with an embedded image is not so plain (are there apps for this job?). I am not so sure that is a Gmail problem, first because I've tried to send the message to other destinations than Gmail and the problem is the same...and why if I send to any destination the same html page by my mail client (Thunderbird) all the results are ok (also for Gmail?).
I shall continue to try... (thanks to all for now)
 
Upvote 0

rbirago

Active Member
Licensed User
Longtime User
what a headache! also embedding the image in the html file the b4j app (like test2.zip) doesn't work (see embedded1 html file), but sending it by my mail client (Thunderbird) the image is ok. So the problem is not in the image itself, but in some other part of the message. I attach also the eml Thunderbird sent file (that works) and the eml B4j sent file (that doesn't show the image)....what a headache!!!
Roberto
 

Attachments

  • HtmlFiles.zip
    12.2 KB · Views: 196
Upvote 0
Top