B4J Question [Solved] Sending HTML Email. Getting Wrong Content from Code Snippet

Dadaista

Active Member
Licensed User
Longtime User
Hi
From this snippet

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
 

Dadaista

Active Member
Licensed User
Longtime User
Hi
Thx @Erel !!

New code snippet throw an error in smtp.send. Line too long

Log says:
B4X:
WARNING: package com.sun.javafx.embed.swing.oldimpl not in javafx.swing

Waiting for debugger to connect...

Program started.

java.lang.RuntimeException: Error sending message: 501 Syntax error - line too long

    at anywheresoftware.b4a.net.SMTPWrapper$1.run(SMTPWrapper.java:338)

    at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)

    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)

    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)

    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630)

    at java.base/java.lang.Thread.run(Thread.java:832)

java.lang.RuntimeException: Error sending message: 501 Syntax error - line too long
 
Upvote 0
Top