SMTP sending an HTML or rich text format message

melamoud

Active Member
Licensed User
Longtime User
Hi,

anyone knows if it is possible (and how to) to send a mail message with picture embedded in the text (not just an attachment)
thanks
 

melamoud

Active Member
Licensed User
Longtime User
I built the code but of course it does not work, I put everything into the body including the encoding (hoping I did it correctly) but I guess unless I have the multi part attribute in the header it wont work
right ?
 
Upvote 0

melamoud

Active Member
Licensed User
Longtime User
trying not working

I even took a base64 code from an email so I'm sure my encoding is not the issue,
here is what I'm sending, is this wrong ? (thats the whole message body)
I tried both with WEB option on or off
I even tried to send this manually from outlook
B4X:
<img src="data:image/jpg;base64,/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAMCAgICAgMCAgIDAwMDBAYEBAQEBAgGBgUGCQgKCgkI
CQkKDA8MCgsOCwkJDRENDg8QEBEQCgwSExIQEw8QEBD/2wBDAQMDAwQDBAgEBAgQCwkLEBAQEBAQ
EBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBD/wAARCABmAIQDASIA
AhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQA
AAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3
ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWm
p6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEA
AwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSEx
BhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElK
U1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZ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OyL8QfEk8F54xmTw7p5G5kJ825k/wCAfdT8T+FfVfw/+Fngr4Zab9h8LaKs
DvgTXMo3zzH/AGm/yK0weS4nMJ+0xhz5txnlORUPqmVLmn/d+A5H4A/AjTfhTpj6pqLRXviK/QLc
3AX5IE/54xZ6KP73evYiQMleccYoIO3aO4pECg4DV9vQoQw8OSmfi+Px9fMq88Vip3nIkHSiiitj
kPiH9ln/AJI3pP8AvN/JaKj/AGVp4n+DWksjgjc3P4LRQB7N8a5PjgmqRj4f/FYeH7fPzRHS7S4z
+MsLn9a4BJv2qSo3ftBKT6/2Dp3/AMi0UUAL537VH/RwK/8Agh07/wCRaPO/ap/6OBX/AMEOnf8A
yLRRQAed+1R/0cCv/gh07/5Fo839qj/o4Ff/AAQ6d/8AItFFAEU8X7T91GYbr48wzIwwVk8P6awP
52tcvffCn4s6lIZr74iaBK56sfCmlg/mLWiiolShNWlFP5G1PEVqP8OTXo2iK1+EPxTspPNtviBo
CP6/8IrpZ/na11NlZftMadEsGn/HO1to1GAsPh3TUA/K1oopQpU6fwRS9EFXE1q38Wbfq2/zLPnf
tUHr+0Cv/gh07/5FoM37VB6/tAr/AOCHTv8A5FoorQxDzv2qP+jgV/8ABDp3/wAi0ed+1R/0cCv/
AIIdO/8AkWiigA879qn/AKOBX/wQ6d/8i0qzftTjOf2gFPH/AEAtO/8AkaiigDsfgz8EbPwR4Csv
D0N6siwEkMAeeB/hRRRQB//Z">
 
Upvote 0

melamoud

Active Member
Licensed User
Longtime User
and this is the code that I'm using anything wrong with it ?

B4X:
Sub encodeAndSendPicture (pic As String)
   Dim Inps As InputStream
   Inps = File.OpenInput(File.DirDefaultExternal,pic)
   Dim count As Int
   Dim buf(99999) As Byte
   count = Inps.ReadBytes(buf,0,99999)
   If (count = -1) Then ToastMessageShow("Failed to load picture",False)
   Inps.Close
   Dim B64 As Base64
   Dim bufEncoded As String
   bufEncoded = B64.EncodeBtoS(buf,0,count)
   Dim SMTP1 As SMTP
   SMTP1.initialize("smtp.gmail.com",465,"myemail","mypassword","SMTP")
   SMTP1.Subject = "test pic"
   SMTP1.To.Add("my target email")
   SMTP1.UseSSL = True
   

   SMTP1.HtmlBody = True
   SMTP1.Body = "<img src=" & QUOTE & "data:image/jpg;base64," & bufEncoded & QUOTE & " />"
   
   Dim os As OutputStream ' keep it in a file for debug
   os = File.OpenOutput(File.DirDefaultExternal,"body.txt",False)   
   os.WriteBytes(SMTP1.Body.GetBytes("UTF8"),0,SMTP1.Body.GetBytes("UTF8").Length)
   os.Flush
   os.Close
   SMTP1.Send
 
Upvote 0

melamoud

Active Member
Licensed User
Longtime User
Who can I asked to add the functionality of changing the header to the SMTP object in net lib ?

It does not seems to be a lot of work.

Thanks
 
Upvote 0

melamoud

Active Member
Licensed User
Longtime User
Anyone can think on a way to use reflection to do this ? to change header attributes of an SMTP object is that even possible ?
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
After looking at SMTP this afternoon, it appears that your problem was the same as the link here. That being an '=' sign is a special character, replacing them with "=3D" appears to work here too, there may be some more chars that need replacing if it doesn't work consistently, take a look here.

See project attached.

I don't know if there is a limit to the size of an image, you'll find that out if needed.

If you try the attached don't forget to change the email account and password and target email.
 

Attachments

  • emailimg.zip
    12.5 KB · Views: 213
Last edited:
Upvote 0
Top