rbirago Active Member Licensed User Longtime User Dec 28, 2019 #1 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
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 Dec 28, 2019 #2 This may of help. How to Embed Images in Email: CID, HTML Inline & Linked Images Learn how to embed images in your email by linking out to the image on a CDN, referencing via a CID tag & linking to an image in HTML. sendgrid.com 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
This may of help. How to Embed Images in Email: CID, HTML Inline & Linked Images Learn how to embed images in your email by linking out to the image on a CDN, referencing via a CID tag & linking to an image in HTML. sendgrid.com Consider to put the Image(s) on your Webhosting and just link the url of this image in the img tags src attribute.
I inakigarm Well-Known Member Licensed User Longtime User Dec 28, 2019 #3 rbirago said: 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. Click to expand... https://www.b4x.com/android/forum/threads/lib-netextras.26902/#content (For B4A) Upvote 0
rbirago said: 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. Click to expand... https://www.b4x.com/android/forum/threads/lib-netextras.26902/#content (For B4A)
rbirago Active Member Licensed User Longtime User Dec 28, 2019 #4 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
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
I inakigarm Well-Known Member Licensed User Longtime User Dec 28, 2019 #5 Can you attach your project's code ? Upvote 0
rbirago Active Member Licensed User Longtime User Dec 29, 2019 #6 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 test2.zip 192.6 KB · Views: 441 Upvote 0
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
I inakigarm Well-Known Member Licensed User Longtime User Dec 29, 2019 #7 rbirago said: here is my test project Click to expand... 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 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 Upvote 0
rbirago said: here is my test project Click to expand... 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 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
rbirago Active Member Licensed User Longtime User Jan 1, 2020 #8 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
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?
I inakigarm Well-Known Member Licensed User Longtime User Jan 2, 2020 #9 rbirago said: What can I try? Click to expand... "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 3) Design the html mail: 4) Copy the Html Source and Paste it on html file (file test.html) 5) Send the mail from B4J Html mail displays fine on Chrome browsers for Yahoo and Gmail mails Upvote 0
rbirago said: What can I try? Click to expand... "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 3) Design the html mail: 4) Copy the Html Source and Paste it on html file (file test.html) 5) Send the mail from B4J Html mail displays fine on Chrome browsers for Yahoo and Gmail mails
rbirago Active Member Licensed User Longtime User Jan 2, 2020 #10 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
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
MicroDrie Well-Known Member Licensed User Longtime User Jan 3, 2020 #11 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. Code: <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
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. Code: <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.
rbirago Active Member Licensed User Longtime User Jan 5, 2020 #12 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
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)
MicroDrie Well-Known Member Licensed User Longtime User Jan 6, 2020 #13 You don't need any app or online conversion tool. Here you can find 4 lines of code to do the B4X solution for a image file to base64 string conversion on the fly and simply merged the result in your HTML page. Upvote 0
You don't need any app or online conversion tool. Here you can find 4 lines of code to do the B4X solution for a image file to base64 string conversion on the fly and simply merged the result in your HTML page.
rbirago Active Member Licensed User Longtime User Jan 7, 2020 #14 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 HtmlFiles.zip 12.2 KB · Views: 438 Upvote 0
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
rbirago Active Member Licensed User Longtime User Jan 7, 2020 #15 Eureka!! (I hope). If I want to send an html mail with one or more images I have to set: B4X: mapHeader.Initialize mapHeader.Put("Content-Transfer-Encoding", "7bit") email.AdditionalHeaders = mapHeader ...and it works! Upvote 0
Eureka!! (I hope). If I want to send an html mail with one or more images I have to set: B4X: mapHeader.Initialize mapHeader.Put("Content-Transfer-Encoding", "7bit") email.AdditionalHeaders = mapHeader ...and it works!