B4J Question [SOLVED] Sending emails to outlook with web based images [SOLVED]

Peter Lewis

Active Member
Licensed User
Longtime User
Hi All

I have been trying to send a html email to Outlook with no luck. the text arrives but nothing else.

I see that the html on SMTP changes the text that I input.

I went to a spam email that someone sent to me which worked and displayed the images from a url. I copied the html code from the outlook message and saved that to an html file.

I then checked the source by opening it in a browser and it works perfectly, and in outlook.

So I imported this html file into my program and assigned it to smtp.body and also I have smtp.HtmlBody = True

But when it arrives it does not display correctly and looking at the source of the message , there are some letters missing

And looking at the data after importing it , looks perfect.


Having these letters missing is the reason why it is not working.

Has any one also experienced this ?

The initial source of the html is attached

Thank you
 

Attachments

  • peterrec.zip
    8.7 KB · Views: 241
Last edited:

Peter Lewis

Active Member
Licensed User
Longtime User
I would accept that BUT, I took an email that was sent to me in OUTLOOK and displayed perfectly. I right clicked and view Source, then saved that into a file which I attached. So THAT CODE DID WORK in OUTLOOK.

I then sent it through B4J SMTP and the results were not good. Somehow characters are missing. This is the problem I am trying to solve. It cannot be a OUTLOOK issue as that is where i got the HTML source. Is there a problem in B4J ??
 
Upvote 0

Dadaista

Active Member
Licensed User
Longtime User
Same problem here. Email sent from my app does not display correctly in outlook
Try to receive the email that you sent from b4J in Gmail... you will see the email correctly...
 
Upvote 0

Peter Lewis

Active Member
Licensed User
Longtime User
Same problem here. Email sent from my app does not display correctly in outlook
Try to receive the email that you sent from b4J in Gmail... you will see the email correctly...
Ok here is the thing,

I took the code in the attached file that came from Outlook and i went to one of my websites and made a php emailing script and sent that file to me via email ..... Guess what , it worked perfectly. the only logical conclusion from that is there is a problem in B4J sending emails .

Here is the php code and I changed the name of the html file

B4X:
<?php
$to = 'peter@justleds.co.za';
$subject = "Send HTML Email Using PHP";

$htmlContent = file_get_contents("email_template.html");

// Set content-type header for sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";

// Additional headers
$headers .= 'From: Peter Lewis<peter@vapelab.durban>' . "\r\n";


// Send email
if(mail($to,$subject,$htmlContent,$headers)):
    $successMsg = 'Email has sent successfully.';
else:
    $errorMsg = 'Email sending fail.';
endif;
?>

and here is the email that arrived in Outlook


and the SAME HTML code through B4J


So unless I am missing something , THIS html code working in Outlook . But not if it is sent via B4J. Please tell me I am wrong
 
Upvote 0

Peter Lewis

Active Member
Licensed User
Longtime User
Just an idea: Did you try another encoding except of UTF8? Try with a windows codepage like 1252 or similar.

Would that be here ?

B4X:
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

I would understand that if it is related to displaying the HTML code but I cannot see they working with random letters missing in the HTML code coming from B4J. That would not solve that problem and I feel that is the problem.

Look at this line that arrived from B4J
B4X:
<meta name=enerator" content=ubSpot"><meta property=g:url" content=ttp://thequestionco-4462250.hs-sites.com/-temporary-slug-
This is the original code
B4X:
<meta name="generator" content="HubSpot"><meta property="og:url" content="http://thequestionco-4462250.hs-sites.com/-temporary-slug

WHY is the G, H, "o , "h, MISSING , just in this one line of code, there are plenty lines , so I cannot believe Codepage will solve this. If the Correct html code went thu and still did not look right , then that could be codepage
 
Upvote 0

Jeffrey Cameron

Well-Known Member
Licensed User
Longtime User
It might be something to do with the double-quotes. HTML accepts either, try changing all of the " to ' in your B4J source before you send it.
 
Upvote 0

Dadaista

Active Member
Licensed User
Longtime User


Try this

B4X:
.Replace("=", "&#61;")
 
Last edited:
Upvote 0

KMatle

Expert
Licensed User
Longtime User
With this vbs script I'm able to send a mail with your html content and it can be viewed correctly in Outlook:

B4X:
Const olByValue = 1
Const olMailItem = 0
    
Dim oOApp
Dim oOMail

Set oOApp = CreateObject("Outlook.Application")
Set oOMail = oOApp.CreateItem(olMailItem)
Const ForReading=1
Set fso = CreateObject("Scripting.FileSystemObject")
BodyText = fso.OpenTextFile("C:\Users\Klaus\Downloads\peterrec\peterrec.html",ForReading).ReadAll

With oOMail
    .To = "MailAddress"
    .SentOnBehalfOfName = "FromAddress"
    .Subject = "Subject"
    .HtmlBody = BodyText
    '.Attachments.Add "C:\somefile.txt", olByValue, 1
    .Save
End With



BTW: What are these outlined question marks good for?



However. I import the html content via file import. Maybe you can import the file in B4J, too to prevent escaping or so. At least you can compare your data to the html body. Maybe this helps...
 
Upvote 0

Peter Lewis

Active Member
Licensed User
Longtime User

I really do not know what those question marks are for. This was an email(SPAM) I received in my inbox . the fact that it arrived and worked , I used it as a baseline.

So you sent the email via vbs and it worked perfectly, I also sent via php and it worked perfectly. This is the reason why i am saying using the jnet Lib , there is something wrong. Maybe @Erel can look into it. This goes to prove that from 2 different other languages and using the exact html code, that these files work.

Why does B4J remove certain messages. I am not a Java or Javascript person but i would be interested in seeing this same file sent to Outlook and see whether it arrives correctly . This will also help us understand if it is an underlying Java / Javascript issue
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
those "?" represent unrecognized characters. the html document
claims to be utf8 but it's not. it's using unsigned bytes, which means
it's using a different character set. i would normally suggest iso8859-1,
which is what windows uses, but the particular character appearing as
a "?" is out of context in this case.

java uses signed bytes. as an example, the character appearing as "?" is
ascii value 226 (0xe2). that means it's unsigned. in java, that would have
a negative value. there are no characters whose values are < 0.

i've not followed the thread closely, but i did take a look at the html doc
since the question about the "?" was raised. whether illegal characters
is relevant to the rest of the thread, i can't say. but i would mention that
in some cases, a "?" is substituted. in others, an exception is thrown.
it's possible that in other cases, a silent swallow is performed.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…