SMTP 503 error in Net library

Oliver Bosse

Member
Licensed User
Longtime User
i copied the example in the tutorial and changed the recipient for my needs.
but i can't get it to work to send an email.

it always throws an error:


java.lang.RuntimeException: Empty writer returned: 503 Bad sequence of commands. You must specify the recipients of a message before you can send it

even with adding two addresses ....

SMTPSender.To.Add("[email protected]")
SMTPSender.To.Add("[email protected]")

it shows

ToastMessageShow(SMTPSender.To.Size, True) = 0

what is possibly wrong here?

oliver
 

Oliver Bosse

Member
Licensed User
Longtime User
it works fine when i use my own google email address and the google smtp server.
but when i use my own smtp server it throws an error.

this is the code...

B4X:
Sub Process_Globals
   Dim SMTP1 As SMTP
End Sub

Sub Activity_Create(FirstTime As Boolean)
    If FirstTime Then
        SMTP1.Initialize("mysmtpserver", 25, "myusername", "mypassword", "SMTP1")
        SMTP1.UseSSL = False
        
    End If
    SMTP1.To.Add("myemailaddress")
    SMTP1.Subject = "This is the subject"
    SMTP1.Body = "This is the message body."
    SMTP1.Send
End Sub

Sub SMTP1_MessageSent(Success As Boolean)
   
    If Success Then
        ToastMessageShow("Message sent successfully", True)
    Else
        ToastMessageShow("Error sending message", True)
        Log(LastException.Message)
    End If
End Sub

i would say that it might be a problem of my smtp server, but i use the same
account data with mozilla thunderbird and it works.
i don't use password encryption in thunderbird and no tls.
 

Oliver Bosse

Member
Licensed User
Longtime User
no, the size of the list is ok. that was my fault.
i've overlooked this...

"Note that the message fields are cleared after this method to allow you to send new messages with the same object."

...so of course in "_MessageSent" it is empty.
 

Oliver Bosse

Member
Licensed User
Longtime User
when i send the message in Activity_Create i get

java.net.SocketException: The connection was reset

when i do it in a Button1_Up it says:

java.lang.RuntimeException: Empty writer returned: 503 Bad sequence of commands. You must specify the recipients of a message before you can send it

it seems as if there is a problem when initializing!?
 

Oliver Bosse

Member
Licensed User
Longtime User
in the case when i send it in Activity_Create i get the connection error.
when i put it in a button_up event like the following....i get a different error


B4X:
Sub Button1_Up
   SMTP1.To.Add("myemailaddress")
        SMTP1.Subject = "This is the subject"
        SMTP1.Body = "This is the message body."
   SMTP1.Send
End Sub

java.lang.RuntimeException: Empty writer returned: 503 Bad sequence of commands. You must specify the recipients of a message before you can send it

...as you can see in the new logfile.
 

Attachments

  • logfile2.txt
    17.7 KB · Views: 432

Oliver Bosse

Member
Licensed User
Longtime User
i changed it to _Click, but i still get:


B4X:
Default buffer size used in BufferedReader constructor. It would be better to be explicit if an 8k-char buffer is required.


Default buffer size used in BufferedWriter constructor. It would be better to be explicit if an 8k-char buffer is required.

java.lang.RuntimeException: Empty writer returned: 503 Bad sequence of commands. You must specify the recipients of a message before you can send it



   at anywheresoftware.b4a.net.SMTPWrapper$1.run(SMTPWrapper.java:248)
   at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
   at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
   at java.util.concurrent.FutureTask.run(FutureTask.java:137)
   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
   at java.lang.Thread.run(Thread.java:1102)
enqueueToast pkg=com.oliverbosse.tester callback=android.app.ITransientNotification$Stub$Proxy@44d38fc0 duration=1


java.lang.RuntimeException: Empty writer returned: 503 Bad sequence of commands. You must specify the recipients of a message before you can send it

notePhoneSignalStrengthLocked: 3->4

gsmAsuToSignal=25


GC freed 1162 objects / 58848 bytes in 159ms

notePhoneSignalStrengthLocked: 4->3


gsmAsuToSignal=12


CTRL-EVENT-STATE-CHANGE id=0 state=6


WPA: Group rekeying completed with 1c:bd:b9:b4:b6:10 [GTK=TKIP]
CTRL-EVENT-STATE-CHANGE id=0 state=7
Event [CTRL-EVENT-STATE-CHANGE id=0 state=6]
Changing supplicant state: COMPLETED ==> GROUP_HANDSHAKE


Event [WPA: Group rekeying completed with 1c:bd:b9:b4:b6:10 [GTK=TKIP]]
Event [CTRL-EVENT-STATE-CHANGE id=0 state=7]
Changing supplicant state: GROUP_HANDSHAKE ==> COMPLETED
GC freed 2995 objects / 193592 bytes in 379ms


GC freed 101 objects / 5448 bytes in 303ms


notePhoneSignalStrengthLocked: 3->4


gsmAsuToSignal=25
 

CarlM

Member
Licensed User
Longtime User
when i send the message in Activity_Create i get

java.net.SocketException: The connection was reset

when i do it in a Button1_Up it says:

java.lang.RuntimeException: Empty writer returned: 503 Bad sequence of commands. You must specify the recipients of a message before you can send it

it seems as if there is a problem when initializing!?

Hi,

I know this is an old thread but does anyone know what was the outcome of this error is because I am getting it too when using the Net Library SMTP.Send for emailing. I have a good wifi connection and can 'see' the internet too.
I am calling from a click event, so its not being called multiple times.

:sign0085:

Thanks,
carl
 

CarlM

Member
Licensed User
Longtime User
B4X:
'Activity module
Sub Process_Globals

   Dim AttachmentFile As String 
   Dim SMTPMail As SMTP
   Dim Subject As String 

End Sub

Sub Globals

Dim cmdClose As Button
Dim cmdSend As Button
Dim txtBody As EditText
Dim txtTo As EditText
Dim txtSubject As EditText

End Sub

Sub Activity_Create(FirstTime As Boolean)

   Activity.LoadLayout("Email")
   If FirstTime Then
        SMTPMail.Initialize(Globals.OutgoingSMTPServer , Globals.SMTPPort, Globals.SMTPUserName,  Globals.SMTPPwd,  "SMTPHandler")
        SMTPMail.UseSSL = False 
   End If
   
   txtTo.Text = Globals.SMTPUserName
   
End Sub

Sub SMTPHandler_MessageSent(Success As Boolean)

   If Success Then
        ToastMessageShow("Message sent successfully", True)
      Activity.Finish
    Else
        ToastMessageShow("Error sending message", True)
      Log(LastException.Message)
      Log(LastException.Message)
    End If
   
End Sub 


Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub


Sub cmdSend_Click

   If txtTo.Text <> "" Then
      ToastMessageShow("sending email...", False)
      SMTPMail.To.Add(txtTo.Text) 
      SMTPMail.Subject  = txtSubject.Text 
      SMTPMail.Body = txtBody.Text 
'      If AttachmentFile <> "" Then
'         SMTPMail.AddAttachment(File.DirDefaultExternal & "/photos", AttachmentFile)
'      End If
      SMTPMail.Sender  = "carl+northandwest.com"
      SMTPMail.Send
   Else
      ToastMessageShow("Please enter an email address!", False)
      txtTo.RequestFocus 
   End If
   
End Sub

Sub cmdClose_Click

   Activity.Finish 
   
End Sub

The three lines to add the attachment file that are remmed made no difference. My smtp details are all valid (can post separately if you need the credentials). My server does not require SSL. The error log I got to print twice so that I could see from the logs which was specific to my error. But the filter gave the exact response as for the first post.
Also I am using a vodafone 858 (own brand??) phone with Android 2.2.2
Many thanks.
Also, the + sign in the Sender property is my user name. I have also tried it with the @ symbol but with the same results.
 

Attachments

  • smtperror.txt
    605 bytes · Views: 372
Last edited:

CarlM

Member
Licensed User
Longtime User
As a follow up..

I googled this and various answers were to try different ports.
I tried 25, 26, 587 and 465. All to no avail.


Send Error from log file::
java.lang.RuntimeException: Empty writer returned: 503-All RCPT commands were rejected with this error:
503-503 sender not yet given
503 Valid RCPT command must precede DATA
at anywheresoftware.b4a.net.SMTPWrapper$1.run(SMTPWrapper.java:248)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
at java.util.concurrent.FutureTask.run(FutureTask.java:137)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
at java.lang.Thread.run(Thread.java:1096)

:confused:
 
Top