Android Question Send mail in http format with images

Filipe Ferreira

Member
Licensed User
Longtime User
Good afternoon,

is it possible to send mail with images inside a table?

like this:


here is my code:
B4X:
    SMTP.Initialize("smtp.gmail.com", 587, "##########@gmail.com", "###########", "SMTP")
    SMTP.StartTLSMode = True
    SMTP.AuthMethod=SMTP.AUTH_LOGIN
    SMTP.To.Add("#####@########")
   
    SMTP.Subject = "Encomenda Fornecedor : " & (FORNECEDOR)
    SMTP.HtmlBody=True
    Dim corpo,corpo1,corpo2,corpo3,corpo4,corpo5,corpo6,corpo7 As String
    corpo="<html><body><style>p{font-family:verdana;display: block;margin: 8px;font-size:12px } table{border: 1px solid black;    border-collapse: collapse;}th {    border: 1px solid black;    padding: 10px;    font-family:verdana;    font-size:13px;    background-color:#c2c2c2;}td {    border: 1px solid black;    padding: 10px;    text-align: left;    font-family:verdana;    font-size:10px;    vertical-align: midlle;} .invisivel {    border: 0px solid white;    padding: 0px;}</style>"
    corpo1= "<p>Boa tarde,"&  "<br/><br/>"
    corpo2= "Segue os dados da encomenda do Fornecedor:" & FORNECEDOR &  "<br/><br/><br/></p> "
    corpo3 =  "<table id=t01>"
    corpo4 = "<tr><th>Fotografia</th><th>Referencia</th><th>Nome</th><th>Designação</th><th>Ref. Fornecedor</th><th>Preço Custo</th><th>Quantidade</th><th>Observações</th><th>Estado</th></tr>"
For i = 0 To lista_artigos_mail.size-1
    Dim partir() As String=Regex.Split("\|",lista_artigos_mail.Get(i))
        corpo5 =corpo5 & "<tr><td><img src=???????????????? & partir(0).Trim&"0.jpg"& "></td><td>" & partir(0) & "</td><td>" &  partir(1) & "</td><td>" &  partir(2) & "</td><td>" &  partir(3) & "</td><td>" &  partir(4) & "</td><td>" &  partir(5) & "</td><td>" &  partir(6) & "</td><td>" &  partir(7) & "</td></tr>"
        SMTP.AddAttachment(File.DirRootExternal,"############/imagens/" & partir(0).Trim&"0.jpg")
Next   
    corpo6  = "</table><br><br/><br/><p>Com os melhores cumprimentos/best regards," &  "<br/><br/>"
    corpo7 =  "Filipe Ferreira"&  "<br/></p> "
    corpo=corpo & corpo1 &corpo2 &corpo3 & corpo4 &corpo5 & corpo6 &corpo7
    SMTP.Body=corpo
    SMTP.Send

the mail is sent with the images attached, but they don't show on table like the next picture


any ideas?

thanks in advanced.
 

DonManfred

Expert
Licensed User
Longtime User
<img src=???????????????? & partir(0).Trim&"0.jpg"& ">
this will not work. Upload the image to a public webspace and reference the imageurl then.

Or convert the image to base64 string and then you could try something like...

B4X:
<img src="data:image/jpg;base64,/*base64-data-string here*/" />

In fact you are adding a second copy of the image. inside the html. The attachment itself is not needed (you can stop adding it if you dont want the attachment in the mail.)
It´s your decision.
 
Upvote 0

Filipe Ferreira

Member
Licensed User
Longtime User


Thank you DonManfred for the quick response.
I used the first option and it worked.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…