B4J Question Connection closed issue, email, outlook

rspitzer

Active Member
When I try to setup an email client for outlook, I keep getting this error, org.apache.commons.net.smtp.SMTPConnectionClosedException: Connection closed without indication.
Can someone point me in a general direction as how to troubleshoot this???
 

teddybear

Well-Known Member
Licensed User
When I try to setup an email client for outlook, I keep getting this error, org.apache.commons.net.smtp.SMTPConnectionClosedException: Connection closed without indication.
Can someone point me in a general direction as how to troubleshoot this???
You'd better post a small project or code snippets(using Code tag).

 
Upvote 0

DarkoT

Active Member
Licensed User
When I try to setup an email client for outlook, I keep getting this error, org.apache.commons.net.smtp.SMTPConnectionClosedException: Connection closed without indication.
Can someone point me in a general direction as how to troubleshoot this???
Maybe this will help you - how to connect with exchange server (in my case exchange on-line):

Example code:
Public Sub SendMail(Subject As String, Body As String, MailTo As String)
    
    Dim MailServer As String = "smtp.office365.com"
    Dim MailPort As String = "587"
    'username for sender - connect to exchange
    Dim MailSender As String = "xxxxxxxxxxxxxxx"
    'password for sender - connect to exchange
    Dim MailPassword As String = "xxxxxxxxxxx"
    
    Smtp.Initialize(MailServer,MailPort,MailSender,MailPassword,"mail")
    Smtp.Subject = Subject
    Smtp.Body = Body

    ' split emails
    Dim emails() As String
    emails = Regex.Split(";",MailTo)
    
    For x = 0 To emails.Length - 1
        Smtp.To.Add(emails(x))
    Next
    
    Smtp.StartTLSMode = True
    Smtp.UseSSL=True
    Smtp.AuthMethod = Smtp.AUTH_LOGIN
    Smtp.HtmlBody = True
    Smtp.Send
    
    Wait For SMTP_MessageSent(Success As Boolean)
    If Success Then
        ' ok - msg send
        
    Else
        ' Error
        ' InsertErrorLog("pgSendEmail", LastException.Message, 1, Main.CurrentUser)
        Log(LastException.Message)
    End If
End Sub
 
Upvote 0

rspitzer

Active Member
Thank all of you for responding.

Code that I use is below. Teddybear wanted me to post it.

Email test:
Sub RunSMTPTest
 
    Dim smtpserver As String = email_settings.Get(0)
    Dim smtpPort As Int = email_settings.Get(1)
    Dim user As String = email_settings.Get(2)
    Dim email_password As String = email_settings.Get(3)

    smtp.Initialize(smtpserver, smtpPort, user, email_password, "smtp")
    smtp.StartTLSMode = email_settings.Get(5)
    smtp.UseSSL = email_settings.Get(6)
    smtp.AuthMethod = smtp.AUTH_LOGIN

    
 
    SendEmail(email_settings.Get(4), user, "subject test1", "body test 1")
 
End Sub

Public Sub SendEmail(ToEmail As String, from As String, Subject As String, body As String)
    
    Try
        smtp.To.Add(ToEmail)
        smtp.Sender = from
        smtp.Body = body
        smtp.Subject = Subject
        smtp.Send
    Catch
        Dim error_text As String
        error_text = LastException.Message
        errorscreen.show_error(Main.prompt(987) & ToEmail & Main.prompt(988) & Subject & error_text,Main.prompt(86),"yellow")
    End Try
 
    wait for SMTP_MessageSent(Success As Boolean)

    If Success Then
        errorscreen.show_error(Main.prompt(989) & ToEmail & Main.prompt(988) & Subject,Main.prompt(86),"yellow")
    Else
        errorscreen.show_error(Main.prompt(987) & ToEmail & Main.prompt(988) & Subject & error_text,Main.prompt(86),"yellow")
    End If
End Sub

For Erel: The port is 587. I have also tried changing the smtp.AuthMethod to smtp.AUTH_LOGIN, smtp.AUTH_PLAIN and AUTH_CRAM_MD5.

For DarkoT, my example code is similar to yours, and I have tried changing the mail server smtp address to your office365 address, originally it was "smtp-mail.outlook.com"

Lastly I have tried toggling the startts and UseSSL enable and disbale combinations.

Just in case the full error is:

error from outlook email:
org.apache.commons.net.smtp.SMTPConnectionClosedException: Connection closed without indication.
    at org.apache.commons.net.smtp.SMTP.__getReply(SMTP.java:199)
    at org.apache.commons.net.smtp.SMTP.__sendCommand(SMTP.java:171)
    at org.apache.commons.net.smtp.SMTP.__sendCommand(SMTP.java:186)
    at org.apache.commons.net.smtp.SMTP.rcpt(SMTP.java:524)
    at org.apache.commons.net.smtp.SMTPClient.addRecipient(SMTPClient.java:314)
    at anywheresoftware.b4a.net.SMTPWrapper$1.run(SMTPWrapper.java:298)
    at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
    at java.base/java.lang.Thread.run(Thread.java:833)


Any additional help would be appreciated as to what to look for here?
 
Upvote 0

DarkoT

Active Member
Licensed User
Thank all of you for responding.

Code that I use is below. Teddybear wanted me to post it.

Email test:
Sub RunSMTPTest
 
    Dim smtpserver As String = email_settings.Get(0)
    Dim smtpPort As Int = email_settings.Get(1)
    Dim user As String = email_settings.Get(2)
    Dim email_password As String = email_settings.Get(3)

    smtp.Initialize(smtpserver, smtpPort, user, email_password, "smtp")
    smtp.StartTLSMode = email_settings.Get(5)
    smtp.UseSSL = email_settings.Get(6)
    smtp.AuthMethod = smtp.AUTH_LOGIN

   
 
    SendEmail(email_settings.Get(4), user, "subject test1", "body test 1")
 
End Sub

Public Sub SendEmail(ToEmail As String, from As String, Subject As String, body As String)
   
    Try
        smtp.To.Add(ToEmail)
        smtp.Sender = from
        smtp.Body = body
        smtp.Subject = Subject
        smtp.Send
    Catch
        Dim error_text As String
        error_text = LastException.Message
        errorscreen.show_error(Main.prompt(987) & ToEmail & Main.prompt(988) & Subject & error_text,Main.prompt(86),"yellow")
    End Try
 
    wait for SMTP_MessageSent(Success As Boolean)

    If Success Then
        errorscreen.show_error(Main.prompt(989) & ToEmail & Main.prompt(988) & Subject,Main.prompt(86),"yellow")
    Else
        errorscreen.show_error(Main.prompt(987) & ToEmail & Main.prompt(988) & Subject & error_text,Main.prompt(86),"yellow")
    End If
End Sub

For Erel: The port is 587. I have also tried changing the smtp.AuthMethod to smtp.AUTH_LOGIN, smtp.AUTH_PLAIN and AUTH_CRAM_MD5.

For DarkoT, my example code is similar to yours, and I have tried changing the mail server smtp address to your office365 address, originally it was "smtp-mail.outlook.com"

Lastly I have tried toggling the startts and UseSSL enable and disbale combinations.

Just in case the full error is:

error from outlook email:
org.apache.commons.net.smtp.SMTPConnectionClosedException: Connection closed without indication.
    at org.apache.commons.net.smtp.SMTP.__getReply(SMTP.java:199)
    at org.apache.commons.net.smtp.SMTP.__sendCommand(SMTP.java:171)
    at org.apache.commons.net.smtp.SMTP.__sendCommand(SMTP.java:186)
    at org.apache.commons.net.smtp.SMTP.rcpt(SMTP.java:524)
    at org.apache.commons.net.smtp.SMTPClient.addRecipient(SMTPClient.java:314)
    at anywheresoftware.b4a.net.SMTPWrapper$1.run(SMTPWrapper.java:298)
    at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
    at java.base/java.lang.Thread.run(Thread.java:833)


Any additional help would be appreciated as to what to look for here?
Uf... What is your original mail server? Exchange 365 (from Microsoft) or you have aditional server provider? I think that you have a problem with SMTP connection; maybe is different port open for SMTP or different SSL Type... My suggestion is - open some new email account on hotmail or outlook.com and try to send over this email - as I doing in my example...
 
Upvote 0
Top