Android Question android.system.ErrnoException: connect failed: ETIMEDOUT (Connection timed out)

Nokia

Active Member
Licensed User
I get them message when I try and send an email from my app using jNet library.

Is this a permission issue?

B4X:
Sub Initialize(ServerAdr As String, Port As Int, User As String, Password As String, _
                        Mode As Int,MailFrom As String ,MailTo As List, pParent As Object, AuthMode As Int, UseHtml As Boolean)
                        
'Initializes the object.
'ServerAdr = Email Server Address
'Port = Email port number
'User = Email user name
'Password = Email password
'Mode: 0 = none mode 1 = StartTLSMode 2 = SSL

    strServerAdr = ServerAdr
    iPort = Port
    strUser = User
    strPassword = Password
    iMode = Mode
    oParent = pParent
    strMailFrom = MailFrom
    strTo = MailTo
    strAuthMode = AuthMode
    chkUseHtml = UseHtml

End Sub

Sub Email_Create_Test(AuthMode As Int)'SendTo As List)

    SMTP.Initialize(strServerAdr, iPort, strUser, strPassword, "SMTP_Test")
    Select Case iMode
        Case 1
            SMTP.StartTLSMode = True
        Case 2
            SMTP.UseSSL = True
    End Select
    
    Select Case AuthMode
        Case "0"
            SMTP.AuthMethod = SMTP.AUTH_PLAIN
        Case "1"
            SMTP.AuthMethod = SMTP.AUTH_LOGIN
        Case "2"
            SMTP.AuthMethod = SMTP.AUTH_CRAM_MD5
    End Select

    SMTP.HtmlBody = chkUseHtml
    SMTP.Sender = strMailFrom
    SMTP.To = strTo
    
    Dim MO As clsMessageOptions
    MO.Initialize()
    SMTP.Subject = MO.defaultMessages(3, True)
    SMTP.Body = MO.defaultMessages(3, False)
                    
    SMTP.Send
    
    For i = 0 To SMTP.To.Size -1
        Log(SMTP.To.Get(i))
    Next
    
    Log(SMTP.Sender)
'    Log(SMTP.to)
    Log(strServerAdr & " " & iPort & " " & strUser & " " & strPassword)
    Log(SMTP.StartTLSMode)
    Log(SMTP.UseSSL)
'    Log(SMTP.AuthMethod)
    
End Sub

Sub SMTP_Test_MessageSent(Success As Boolean)

    Dim msg As String = ""
    Dim sError As String = ""
    Dim RCPT As String
        
    For i = 0 To strTo.Size - 1
        RCPT = RCPT & strTo.Get(i) & "; "
    Next
    
    msg = "Message sent to " & RCPT
    
    If Success Then
        'msg = "Message sent to " & RCPT
        sError = "Handed email to server successfully"
    Else
        'msg = LastException.Message
        sError = LastException.Message
    End If
    
    Dim rR(4) As Object
    rR(0) = "Email_Test"
    rR(1) = msg
    rR(2) = Success
    rR(3) = sError
    
    Log(sError)
        
    CallSub3(oParent, "email_sent_event", Success, sError)
    CallSub2(oParent,"MessageHandler",rR)
    
End Sub
 

Nokia

Active Member
Licensed User
fixed the issue by updating my code:

B4X:
    Select Case iMode
        Case 1
            SMTP.StartTLSMode = True
            SMTP.UseSSL = False
        Case 2
            SMTP.StartTLSMode = False
            SMTP.UseSSL = True
            TM.InitializeAcceptAll
            SMTP.SetCustomSSLTrustManager(TM)
    End Select
 
Top