URL in the mail body

joseanquiles

Member
Licensed User
Longtime User
Hello everyone,
I am trying to put a URL in the body of a SMTP object.

smtp.Body = "http://host/action?a=40.23"

eMail is correctly sent.
However, when I read it the mail, the URL is altered:

http://host/[email protected]

It seems that =40 is a special code or similar, and it is changed to @
How can I solve this problem?

Thank you in advance.
Jose Antonio
 

JonPM

Well-Known Member
Licensed User
Longtime User
Don't have B4A here right now to test this, but maybe something like this might work?

smtp.Body = "http://host/action?a=" & "40.23"
 
Upvote 0

joseanquiles

Member
Licensed User
Longtime User
Hi JonPM
I have just tried it, but it doesn't work.
Perhaps it's needed to escape the URL o something like this, but unfortunately I have no experience with B4A :sign0148:
Thank you in any case JonPM
 
Upvote 0

joseanquiles

Member
Licensed User
Longtime User
It doesn't seem a problem with the mail client, because I have tested with Microsoft Outlook, Gmail on PC, Gmail on Android and K9 on Android.
All mail clients show @ instead of =40.
Could you show me your B4A code working?
Thank you
 
Upvote 0

NJDude

Expert
Licensed User
Longtime User
I tested it using this code:

B4X:
Dim Message As Intent

Uri = "mailto:?subject=Some Test&body=http://host/action?a=40.23" 
Message.Initialize(Message.ACTION_VIEW, Uri)

StartActivity(Message)

And this one:

B4X:
Dim Message As Email
Message.To.Add("[email protected]") 'Email address
Message.body = "http://host/action?a=40.23" 'Email main text 
Message.Attachments.Add("") 
StartActivity(Message.GetIntent)

EDIT TO ADD: Ok, I was able to replicate your error, it happens if you use the NET library and a code like the one below:
B4X:
Msg = "http://host/action?a=40.23"
            
SMTP.Initialize("smtp.MyServer.com", 25, "[email protected]", "mypassword", "SMTP")
SMTP.To.Add("[email protected]")    
SMTP.Subject = "Email Test"    
SMTP.Body = Msg   
SMTP.Send

A bug maybe?
 
Last edited:
Upvote 0

joseanquiles

Member
Licensed User
Longtime User
Exactly.
The error occurs using the NET library.
Using intent and mail, it works.
Does anyone know about this possible bug? Is a workaround possible? Escaping, etc......
 
Upvote 0

JorgeMC

Member
Licensed User
Longtime User
I keep having the same problem, I send this URL to show and I can not, the code I have is this:

B4X:
Sub GPS_LocationChanged (Location1 As Location)
   
   lon = Location1.ConvertToSeconds(Location1.Longitude)
   lat= Location1.ConvertToSeconds(Location1.Latitude)
   SMTP.Initialize("smtp.gmail.com", 465, "[email protected]", "pass", "SMTP")
    SMTP.UseSSL = True 
   SMTP.To.Add("[email protected]")
    SMTP.Subject = "Subject"
    SMTP.HtmlBody= True 
    SMTP.Body = "http://maps.google.com/staticmap?center= "&Location1.Latitude&","& Location1.Longitude&"&zoom=14&size=400x400&markers= "&Location1.Latitude&","& Location1.Longitude&"&key=12345"
    SMTP.Send
   
   
End Sub

The URL that receives the mail is this:

B4X:
http://maps.google.com/[email protected],-1.23456789&zoom&size@0x400&[email protected],-1.23456789&key�345

The Key to Google also eats the first two characters.

Can anyone help me?

I tried both putting SMTP.HtmlBody False, as removing or placing before the = sign espacion
 
Last edited:
Upvote 0

sheriffporter

Member
Licensed User
Longtime User
Check a hex editor, it turns out that 40 is the hex code for the @ symbol. I am betting that is getting "resolved" by one end or the other....
 
Upvote 0

joseanquiles

Member
Licensed User
Longtime User
Sheriffporter, I don't understand your porposal (my bad Engliish sure :sign0013:).
I can't solve anything in the email client software. I need to solve it in the sender, that is, my Android program using NET library.
 
Upvote 0

joseanquiles

Member
Licensed User
Longtime User
It could be a bug of the NET library, couldn't it?

Could I get the source code for this library in order to try to solve the bug?
 
Upvote 0

wl

Well-Known Member
Licensed User
Longtime User
It is not a bug of the NET library (it seems).

You can download a Java decompiler (such as Cavaj) and decompile the classed inside the JAR file.

It seems that the NET class is a wrapper around the apache commons library and sending the message is done by SMTPClient.sendMessageData.

I believe the bug is there somewhere.

The Apache library also contains methods sendShortMessageData and sendSimpleMessage, which might help if we'd write a wrapper method around it...

But first: let's try to see what is exactly wrong ...
 
Upvote 0

joseanquiles

Member
Licensed User
Longtime User
Hello wl,
I don't think the solution is decompile java code, because it usually comes to errors...
Why did you say "it is not a bug" ?
What is wrong with my code? I think I am using the library as documentation points out. However, in the case of equals sign followed by numbers, mail body is altered.
 
Upvote 0

wl

Well-Known Member
Licensed User
Longtime User
In first instance I'm just decompiling to see what is wrong.

What I meant was that; as far as I can see, there is nothing wrong with the SMTP wrapper class Erel wrote.
 
Upvote 0

joseanquiles

Member
Licensed User
Longtime User
Hello wl,
in the first place, I will thank you for your effort.

I have just decompile de SMPT wrapper class and I have seen something "strange":
When there aren't attachments, the "Content-Transfer-Encoding" mail header is set to "quoted-printable". However, when there is one (or more) attachments, this header is not set.
I have been searching for this header and I have found this:

5.1. Quoted-Printable Content-Transfer-Encoding

"Rule #1: (General 8-bit representation) Any octet, except those indicating a line break according to the newline convention of the canonical (standard) form of the data being encoded, may be represented by an "=" followed by a two digit hexadecimal representation of the octet's value...."

I think that is the problem.

I will try to send the mail with one attachment.

Regards.
 
Upvote 0

joseanquiles

Member
Licensed User
Longtime User
IT WORKS !!!

I have added a single attachment, and then, URL in the mail body gets ok.
Perhaps the fine solution should be a boolean variable in the SMTP class to set or unset the header "Content-Transfer-Encoding=quoted-printable"...... Next library version Erel?

Meanwhile, I will add some "fictitious" attachment.

Thanks everybody.
 
Upvote 0

wl

Well-Known Member
Licensed User
Longtime User
Hi,

This is exactly what I wanted to suggest as well because I saw the same code.

As it is not that hard to create libraries, especially not if you only have to add a few lines of code, you could try to make a modified version of it (as I did for POP3).

Wim
 
Upvote 0

JorgeMC

Member
Licensed User
Longtime User
IT WORKS !!!

I have added a single attachment, and then, URL in the mail body gets ok.
Perhaps the fine solution should be a boolean variable in the SMTP class to set or unset the header "Content-Transfer-Encoding=quoted-printable"...... Next library version Erel?

Meanwhile, I will add some "fictitious" attachment.

Thanks everybody.

So that way you have been unsuccessful? You can put the code as you have solved? I'm desperate
 
Upvote 0

joseanquiles

Member
Licensed User
Longtime User
Of course, Jorge.

B4X:
'Activity module
Sub Process_Globals
   ' email
   Dim mySMTP As SMTP
End Sub

B4X:
        ' button callback
   ' send mail
   mySMTP.Initialize("smtp.gmail.com", 465, "[email protected]", "password", "SMTP")
   mySMTP.UseSSL = True
   mySMTP.To.Add("[email protected]")
   mySMTP.Subject = "Subject"
   mySMTP.Body = "located at http://maps.google.com/maps?q=" & latitud & ",+" & longitud & "&iwloc=A&hl=es"
   mySMTP.AddAttachment(File.DirAssets,"foo.png")   ' Anything
   mySMTP.Send

I have to send a unuseful attachment to skyp the quoted-printable header.
By this way, the URL is ok in the received mail.

I hope it answers you.
 
Upvote 0
Top