Android Question SMTP - Problem

Chris Guanzon

Active Member
Licensed User
Longtime User
Hi, this is the first time I am going to use .Net library. I want to use the SMTP Object to send an email, but I am getting this error:

B4X:
java.lang.RuntimeException: Empty writer returned: 503-All RCPT commands were rejected with this error:
503-Sender verify failed
503 Valid RCPT command must precede DATA

This is my code:


B4X:
Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Layout")
    
    If FirstTime Then
        SMTP.Initialize("mail.mydomain.com", 587, "[email protected]", "password", "SMTP")
        SMTP.StartTLSMode = false
    End If
    SMTP.To.Add("[email protected]")
    SMTP.Subject = "This is the subject"
    SMTP.Body = "This is the message body."
    'SMTP.AddAttachment(File.DirRootExternal, "somefile")
    SMTP.Send
End Sub

If I change SMTP.StartTLSMode to True, I'm getting the same error. But if I change the port to 465 and SMTP.StartTLSMode = True, I'm getting this (java.net.SocketTimeoutException: Read timed out). Same if I change SMTP.StartTLSMode = False with port 465.
I also tried using SMTP.UseSSL = True, this is the error:

B4X:
java.lang.RuntimeException: Empty writer returned: 503-All RCPT commands were rejected with this error:
503-Sender verify failed
503 Valid RCPT command must precede DATA

If I set SMTP.UseSSL to false, this is the err message: (java.net.SocketTimeoutException: Read timed out).
 

drgottjr

Expert
Licensed User
Longtime User
does the server permit relaying? are you sure you've followed its documentation to the letter? (i'd like to look at the documentation; which server is it? i don't need your credentials.)
 
Upvote 0

Chris Guanzon

Active Member
Licensed User
Longtime User
does the server permit relaying? are you sure you've followed its documentation to the letter? (i'd like to look at the documentation; which server is it? i don't need your credentials.)

below is the screenshot settings for smtp.
1604457881480.png
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
the settings are only part of the story. there are other factors which, presumably, would be detailed in the server's documentation. what you've tried so far seems to conform to the settings you show, so you'll have to read the rest of the documentation. when you use your smtp server from outside its network, success is not always based simply on login/password. it goes back many years to a time when, eg, i could use your smtp server to send spam. it was called relaying. in those days, you didn't even need a login/password. protections have since been put in place.

take gmail, for example: you have to have authorization from google to use gmail as an smtp server from an app. it doesn't matter that you have a login/password. your server may have a similar requirement. if i were an smtp server, i know i would.

some stmp servers require checking for mail (pop) before they allow outgoing mail (smtp). it's called pop over smtp. your server could have such a requirement.

if you don't want to check the documentation, you should ask the smtp administrator what you have to do to send email from an email client.
 
Upvote 0
Top