Hi
From this snippet
I get wrong content
The HTML code from file Downloaded is (before EncodeBase64)
I am getting...
PCFET0NUWVBFIGh0bWw+CjxodG1sPgogIDxoZWFkPgogICAgPG1ldGEgaHR0cC1lcXVpdj0iY29udGVudC10eXBlIiBjb250ZW50PSJ0ZXh0L2h0bWw7IGNoYXJzZXQ9VVRGLTgiPgogIDwvaGVhZD4KICA8Ym9keT4KICAgIDxwPjwvcD4KICAgIDxoMz5IYXMgcmVjaWJpZG8gZXN0ZSBlbWFpbCBkZXNkZSBDYWphIFZlbnRhIFtXaW5kb3dzXTwvaDM+CiAgICA8cD48L3A+CiAgICA8cD48L3A+CiAgICA8aDQ+RmljaGVybyBBZGp1bnRvOjwvaDQ+CiAgICA8cD48L3A+CiAgICA8aDQgc3R5bGU9Im1hcmdpbi1sZWZ0OiA0MHB4OyI+ZW5lcm8oMjAyMSktbWFyem8oMjAyMSkueGxzPC9oND4KICAgIDxwPjwvcD4KICAgIAogIDwvYm9keT4KPC9odG1sPgo
after of..
My code is
How can I solve it?
Thank you in advance
From this snippet
[B4X] Solving encoding issues with html mails sent with SMTP (Net library)
Encoding the html text with base64 avoids encoding issues, especially with MS Outlook. This code is compatible with B4A and B4J: Dim su As StringUtils smtp.Body = su.EncodeBase64(html.GetBytes("utf8")) 'html = the html body smtp.AdditionalHeaders.Put("Content-Transfer-Encoding", "BASE64")...
www.b4x.com
I get wrong content
The HTML code from file Downloaded is (before EncodeBase64)
HTML:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body>
<p></p>
<h3>Has recibido este email desde Caja Venta [Windows]</h3>
<p></p>
<p></p>
<h4>Fichero Adjunto:</h4>
<p></p>
<h4 style="margin-left: 40px;">enero(2021)-marzo(2021).xls</h4>
<p></p>
</body>
</html>
I am getting...
PCFET0NUWVBFIGh0bWw+CjxodG1sPgogIDxoZWFkPgogICAgPG1ldGEgaHR0cC1lcXVpdj0iY29udGVudC10eXBlIiBjb250ZW50PSJ0ZXh0L2h0bWw7IGNoYXJzZXQ9VVRGLTgiPgogIDwvaGVhZD4KICA8Ym9keT4KICAgIDxwPjwvcD4KICAgIDxoMz5IYXMgcmVjaWJpZG8gZXN0ZSBlbWFpbCBkZXNkZSBDYWphIFZlbnRhIFtXaW5kb3dzXTwvaDM+CiAgICA8cD48L3A+CiAgICA8cD48L3A+CiAgICA8aDQ+RmljaGVybyBBZGp1bnRvOjwvaDQ+CiAgICA8cD48L3A+CiAgICA8aDQgc3R5bGU9Im1hcmdpbi1sZWZ0OiA0MHB4OyI+ZW5lcm8oMjAyMSktbWFyem8oMjAyMSkueGxzPC9oND4KICAgIDxwPjwvcD4KICAgIAogIDwvYm9keT4KPC9odG1sPgo
after of..
B4X:
SMTP.Body = su.EncodeBase64(sBody.GetBytes("utf8"))
SMTP.AdditionalHeaders.Put("Content-Transfer-Encoding", "BASE64")
My code is
B4X:
Sub MandaEmailConFichero(sFile As String, sEmailR As String, sEmailE As String, sServidor As String, sClave As String, iPuerto As Int)
Dim su As StringUtils
Dim sBody As String = ""
Dim url As String = "myURL://myHTMLFile.html"
SMTP.Initialize(sServidor, iPuerto, sEmailE, sClave, "SMTP")
If iPuerto = 587 Then
SMTP.StartTLSMode = True
Else
SMTP.UseSSL = True
End If
SMTP.HtmlBody = True
SMTP.To.Add(sEmailR)
SMTP.Subject = "[APP] File: " & sFile
SMTP.AddAttachment(File.DirTemp, sFile)
Dim j As HttpJob
j.Initialize("", Me)
j.Download(url)
Wait For (j) JobDone (j As HttpJob)
If j.Success Then
Dim out As OutputStream = File.OpenOutput(File.DirTemp, "lomando", False)
File.Copy2(j.GetInputStream, out)
out.Close '<------ very important
Dim FicheroEmail As TextReader
FicheroEmail.Initialize(File.OpenInput(File.DirTemp, "lomando"))
sBody = FicheroEmail.ReadAll 'LEE TODO Y CIERRA EL FICHERO
sBody = sBody.Replace("sDameTipoPlataforma", sDameTipoPlataforma)
sBody = sBody.Replace("sFile", sFile)
Log(sBody)
End If
j.Release
SMTP.Body = su.EncodeBase64(sBody.GetBytes("utf8"))
SMTP.AdditionalHeaders.Put("Content-Transfer-Encoding", "BASE64")
SMTP.Send
File.Delete(File.DirTemp, "lomando")
End Sub
How can I solve it?
Thank you in advance