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

<meta name=enerator" content=ubSpot"><meta property=g:url" content=ttp://thequestionco-4462250.hs-sites.com/-temporary-slug-
<meta name=-apple-disable-message-reformatting">
<meta http-equiv=ontent-Type" content=ext/html; charset=F-8">
<meta http-equiv=-UA-Compatible" content=Eíge">
<meta name=iewport" content=idthÞvice-width, initial-scale=0">
<!--[if gte mso 9]>
<xml>
<o:OfficeDocumentSettings>
<o:AllowPNG/>
<o:pixelsPerInch>96</o:pixelsPerInch>
</o:OfficeDocumentSettings>
</xml>
And looking at the data after importing it , looks perfect.
Qt: Untested Windows version 10.0 detected!
Qt: Untested Windows version 10.0 detected!
Qt: Untested Windows version 10.0 detected!
Qt: Untested Windows version 10.0 detected!
Qt: Untested Windows version 10.0 detected!
Qt: Untested Windows version 10.0 detected!
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional //EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xmlns:eek:="urn:schemas-microsoft-com:eek:ffice:eek:ffice" xmlns:v="urn:schemas-microsoft-com:vml" lang="en"><head>
<title>❓Brand New 2021 Trivia Database❓</title>
<meta property="og:title" content="❓Brand New 2021 Trivia Database❓">
<meta name="twitter:title" content="❓Brand New 2021 Trivia Database❓">



<meta name="x-apple-disable-message-reformatting">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!--[if gte mso 9]>
<xml>
<o:OfficeDocumentSettings>
<o:AllowPNG/>
<o:pixelsPerInch>96</o:pixelsPerInch>
</o:OfficeDocumentSettings>
</xml>

<style>
ul > li {
text-indent: -1em;
}
</style>
<![endif]-->
<!--[if mso]>
<style type="text/css">
body, td {font-family: Arial, Helvetica, sans-serif;}
</style>
<![endif]-->



<meta name="generator" content="HubSpot"><meta property="og:url" content="http://thequestionco-4462250.hs-sites.com/-temporary-slug-d08f7069-7440-430f-99f7-05403c4344b5"><meta name="robots" content="noindex,follow"><!--[if !((mso)|(IE))]><!-- --><style type="text/css">.moz-text-html .hse-column-container{max-width:600px !important;width:600px !important}
.moz-text-html .hse-column{display:table-cell;vertical-align:top}.moz-text-html .hse-section .hse-size-5{max-width:250px !important;width:250px !important}


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: 163
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... :rolleyes:
 
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... :rolleyes:
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 = '[email protected]';
$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<[email protected]>' . "\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

1614364943321.png

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
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


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

1614433472771.png


BTW: What are these outlined question marks good for?

1614433852866.png


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
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

View attachment 108810

BTW: What are these outlined question marks good for?

View attachment 108811

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...

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
Top