B4J Question message has lines too long for transport - smtp email

prajinpraveen

Active Member
Licensed User
Longtime User
Good day

Message delivery fails with the error message - message has lines too long for transport

Usually this happens when a line goes over 1000 characters, as that’s the RFC required limit.

So, i added CRLF after all my HTML tags. Then, I figured the problem is with

esmtp.Body = su.EncodeBase64(emailbody.GetBytes("utf8"))

repalce this with esmtp.Body = emailbody, and the email goes through successfully.

any suggestions?
 

prajinpraveen

Active Member
Licensed User
Longtime User
Spoke too soon. here is the solution


B4X:
Private Sub EncodeBase64WithLineBreaks (bytes() As Byte) As String
    Dim su As StringUtils
    Dim s As String = su.EncodeBase64(bytes)
    If s.Length <= 76 Then Return s
    Dim sb As StringBuilder
    sb.Initialize
    Dim linelength As Int
    For i = 0 To s.Length - 1
        If linelength = 76 Then
            sb.Append(Chr(13) & Chr(10))
            linelength = 0
        End If
        sb.Append(s.CharAt(i))
        linelength = linelength + 1
    Next
    Return sb.ToString
End Sub
 
Upvote 0
Top