Using Net Library with HTML Body

SeaCay

Member
Licensed User
Longtime User
Hello All,

I am using (testing) the Net library. I have the HTML Body set to true and I add in a bit of HTML code to the body as so
B4X:
        SMTPMsg.HtmlBody = True
        SMTPMsg.Body = "1, <B>This</B> is in <div style=""color:#FF0000"";>red</div>"
From the above, I am bolding the word 'This' and the word 'red' should appear in red.

When I check the message in Outlook, I see
  1. 'This ' is indeed bold.
  2. 'red' is in black
When I check the source in Outlook=>View Source, I see
  1. <B> This</B> is in <span style=3D'color:#ff0000;'>red</span>

Notes
  1. <div> is changed to <span>
  2. 3D has appeared in the string
  3. double quotes are now single quotes

All I want is red text.
Can anyone explain what is happening please?
I know that many would probably wish to answer with don't use Outlook, but that is not an option.

regards

SeaCay
 

SeaCay

Member
Licensed User
Longtime User
Hi Erel,

Thanks for your incredibly fast reply.
I might try with Thunderbird but for production it will need to be Outlook.

regards

SeaCay
 
Upvote 0

SeaCay

Member
Licensed User
Longtime User
I changed the "to" address to go an account with a Thunderbird client. And that's all I changed.
Now the message fails to send and returns the error message:
java.lang.RuntimeException: Empty writer returned: 503 Bad sequence of commands​

Any ideas?

regards

SeaCay
 
Upvote 0

SeaCay

Member
Licensed User
Longtime User
This is strange. Make sure that your SMTP parameters are correct.
Hello Erel,

Yes this is indeed strange because when I change the recipient back to the original (and that's all I change), I have no issue with sending the message. However I still have the original issue.

regards

SeaCay
 
Upvote 0

SeaCay

Member
Licensed User
Longtime User
Hello Erel and MotoMusher

Further testing reveals that the '3D' insertion is the issue to my original problem. Removing the '3D' from the source has the result showing correctly.
My code is as taken from the examples on the Net library documentation page and from the original posting. Except I have placed the SMTP message construction on a button.

here's my current code (accounts, servers and passwords have been change for obvious reasons)

B4X:
Sub Activity_Create(FirstTime As Boolean)
  Activity.LoadLayout("Dummy")
  InternalDisk = "sdcard"
  ExternalDisk = InternalDisk & "/external_sd"
  ESTargetDrive = ExternalDisk
  If FirstTime Then
    SMTPMsg.Initialize("mail.myserver.com.au", 587, "anaccount", "somepw", "SMTPMsg")   ' does not require STARTTLS
  End If
End Sub

Sub Button1_Click
    SMTPMsg.To.Add("someone@somewhere.com.au")  ' add a recipient
    SMTPMsg.Subject = "New Email Technique"   ' add a subject
    SMTPMsg.HtmlBody = True   ' Using HTML Body
    SMTPMsg.Body = "<P>1, <B>This</B> is in <span style='color:red'>red</span></P>"  ' an equals sign
    If File.Exists(ESTargetDrive, "TestFile.txt") Then    'add an attachment
      Log("Attachment found")
      SMTPMsg.AddAttachment(ESTargetDrive, "TestFile.txt")
    Else
      Log("Attachment not found")
    End If
    SMTPMsg.Send     ' send the message
End Sub

Sub SMTPMsg_MessageSent(Success As Boolean)
     Log("Msg Sent is " & Success)
     If Success Then
       ToastMessageShow("Message sent successfully", True)
     Else
       ToastMessageShow("Error sending message", True)
       Log(LastException.Message)
     End If
End Sub

As I have lifted and used the code almost verbatim from the B4A web pages, I am unable to see why this should not flow the correctly from Sender to Recipient.

regards

SeaCay
 
Upvote 0

SeaCay

Member
Licensed User
Longtime User
Does this code work correctly?
Hello Erel,

The code I posted in my previous message does not work. Somewhere between hitting the button to send and receiving the message on a client email program the '3D' is being inserted. I have no control over the insertion of the '3d'.

regards

SeaCcay
 
Upvote 0

SeaCay

Member
Licensed User
Longtime User
Does this code work correctly?
Hello Erel,

I am pleased to report that, Yes, the new Net Library does fix the problem.
Many thanks for fixing the library.
I would also like to thank MotoMusher and look forward to reading that their issue is resolved shortly.

regards

SeaCay
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
I am showing v 1.36 for NET library. I still get =3D with htmlbody= false, BUT within HTMLbody = True, it works.

Any chance we can get that change for plaintext?

Without this change the '=' equal character was treated incorrectly by some of the clients. I can make this "feature" optional.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…