Hi.
We are using SMTP to send a mail from an SMTP server which isn’t public. We do have access to this SMTP through some firewall rules. I’ve a simple test application written in c# that successfully sends an email through the described configuration. The code in c# is almost identical to the code we developed in B4J.
We want to send the same way a mail using B4J. The reason is because we have a Web Application written in B4J that should send that mail. Here is the class we implemented and use in B4J:
We call it like that:
I did many tests. I tried to set AuthMethod. I tried to set MailFrom manually, as I see this is the command related with SMTP MAIL command. I do get the following error:
I know the provided code is working with yahoo mail. But we have to use that specific exchanges server through vpn to send mail.
No success until now.
So if someone has an idea what should I change to make this work it will be welcome.
Thanks
Andreas.
We are using SMTP to send a mail from an SMTP server which isn’t public. We do have access to this SMTP through some firewall rules. I’ve a simple test application written in c# that successfully sends an email through the described configuration. The code in c# is almost identical to the code we developed in B4J.
We want to send the same way a mail using B4J. The reason is because we have a Web Application written in B4J that should send that mail. Here is the class we implemented and use in B4J:
SendMail:
Sub Class_Globals
Private SMTP As SMTP
End Sub
'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize
Dim mailServer, mailServerPort, mailServerUserName, mailServerPassword, security, mailSender As String
Try
mailSender = Main.settings.Get("MailSender")
mailServer = Main.settings.Get("MailServer")
mailServerPort = Main.settings.Get("MailServerPort")
mailServerUserName = Main.settings.Get("MailServerUserName")
mailServerPassword = Main.settings.Get("MailServerPassword")
security = Main.settings.Get("Security")
SMTP.Initialize(mailServer, mailServerPort, mailServerUserName, mailServerPassword, "SMTP")
SMTP.Sender = mailSender
' Select Main.settings.Get("AuthMethod")
' Case "AUTH_PLAIN"
' SMTP.AuthMethod = SMTP.AUTH_PLAIN
' Case "AUTH_LOGIN"
' SMTP.AuthMethod = SMTP.AUTH_LOGIN
' Case "AUTH_CRAM_MD5"
' SMTP.AuthMethod = SMTP.AUTH_CRAM_MD5
' Case Else
' SMTP.AuthMethod = SMTP.AUTH_PLAIN
' End Select
'
' Select security.ToUpperCase
' Case "SSL"
' SMTP.UseSSL = True
' SMTP.StartTLSMode = False
' Case "TLS"
' SMTP.StartTLSMode = True
' SMTP.UseSSL = False
' Case Else
' SMTP.UseSSL = False
' SMTP.StartTLSMode = False
' End Select
Log("mailSender: " & mailSender)
Log("mailServerPort: " & mailServerPort)
Log("mailServerUserName: " & mailServerUserName)
Log("mailServerPassword: " & mailServerPassword)
Log("UseSSL: " & SMTP.UseSSL)
Log("StartTLSMode: " & SMTP.StartTLSMode)
Catch
Log("SendMail Initialize")
Log(LastException)
End Try
End Sub
public Sub sendMessage(recipients As List, subject As String, cc As List, bcc As List, body As String, htmlBody As Boolean)
Try
SMTP.Body = body
SMTP.HtmlBody = htmlBody
SMTP.To = recipients
If cc.Size > 0 Then SMTP.CC = cc
If bcc.Size > 0 Then SMTP.BCC = bcc
SMTP.Subject = subject
' Log(SMTP.To)
' Log(SMTP.CC)
' Log(SMTP.BCC)
' Log(SMTP.HtmlBody)
' Log(SMTP.Body)
SMTP.Send
Catch
' Log("sendMessage")
Log("SendMail sendMessage")
Log(LastException)
End Try
End Sub
Private Sub SMTP_MessageSent(Success As Boolean)
Try
' Log(Success)
If Not(Success) Then
Log("SendMail MessageSent Failure")
Log(LastException.Message)
End If
Catch
' Log("EventName_MessageSent")
Log("SendMail MessageSent Error")
Log(LastException)
End Try
End Sub
Calling SendMail Class.:
Dim testMail As SendMail
Dim recp, cc, bcc As List
recp.Initialize
cc.Initialize
bcc.Initialize
recp.Add("<[email protected]>")
Try
testMail.Initialize
LogDebug("sendMessage")
testMail.sendMessage(recp, "Test mail", cc, bcc, "This is a mail test!", False)
Catch
fx.Msgbox(Null, LastException.Message, "Error:")
Log("ButtonTestMail_Click")
Log(LastException)
End Try
Error message::
java.lang.RuntimeException: Empty writer returned: 503 5.5.2 Need mail command
at b4j/anywheresoftware.b4a.net.SMTPWrapper$1.run(Unknown Source)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.base/java.lang.Thread.run(Unknown Source)
SendMail MessageSent Failure
java.lang.RuntimeException: Empty writer returned: 503 5.5.2 Need mail command
No success until now.
So if someone has an idea what should I change to make this work it will be welcome.
Thanks
Andreas.