Email not sent in console application

  1. 2 years ago

    I have made a console application which check backup file on Ftp and then sends a email
    In app.run i have written this code and called the method to Send an email:

    Dim objTimer As new CustomTimer
    objTimer.Mode = Timer.ModeMultiple
    do
      App.DoEvents 3000
      ProSendEmail(CurrentDate)
    loop

    The method to send email is:

    EmailSocket = new  MailSocket //Mailsocket is SMTPSecureSocket
    Dim mail As New EmailMessage
    EmailSocket.Address = "mail.server" // your SMTP email server
    EmailSocket.Port =123
    EmailSocket.Secure=True
    EmailSocket.ConnectionType=3
    EmailSocket.Username="xyz@gmail.com"
    EmailSocket.Password="123"
    EmailSocket.Connect
    
    While 1=1 
      EmailSocket.Connect 
      If EmailSocket.IsConnected Then Exit
    Wend
    
    mail.FromAddress = "xyz@gmail.com"
    mail.Subject =  "Database backup is missing for Date "
    mail.AddRecipient("xyz@gmail.com")
    mail.BodyPlainText ="Test email"
    
    EmailSocket.DeleteAllMessages
    EmailSocket.Messages.Append(mail)
    EmailSocket.SendMail

    The mail is not sent. What am I doing wrong in this?

    Thanks in advance

    I have a console app that sends a status email.
    Code similar to the following, placed at the end of the SendEmail method, is necessary to allow the socket time to send the email:

      do until socket.Messages.Ubound = -1
        socket.Poll
      loop
  2. Christian S

    9 Jun 2017 Pre-Release Testers, Xojo Pro, XDC Speakers, Third Party Store Germany

    Please run a loop calling app.DoEvents or at least socket.poll to give time to the socket.

  3. Wayne G

    9 Jun 2017 Pre-Release Testers, Xojo Pro Auckland, New Zealand

    The SMTP Secure Socket manages its own connection, so remove the code

    EmailSocket.Connect
    
    While 1=1 
      EmailSocket.Connect 
      If EmailSocket.IsConnected Then Exit
    Wend

    from your method.

    In the run event handler you are executing your event loop every 3 seconds and then executing prosendmail which I'm assuming is the name of the second method. Repeatedly running sendmail will cause the SMTPSocket to fail to complete any send, wait until the MailSent event has fired before sending further mail.

    This class is what I use in Web Apps to send email from multiple sessions while avoiding these collisions.

  4. Jared F

    9 Jun 2017 Pre-Release Testers, Xojo Pro Answer Milwaukee, WI
    Edited 2 years ago

    I have a console app that sends a status email.
    Code similar to the following, placed at the end of the SendEmail method, is necessary to allow the socket time to send the email:

      do until socket.Messages.Ubound = -1
        socket.Poll
      loop
  5. Tim H

    9 Jun 2017 Pre-Release Testers Portland, OR USA

    Run your main loop more frequently, like 10ms, and send your email from a timer.

  6. 9 weeks ago

    Hi,
    I have the same problem.
    in the console app I can not send email
    socket error 103 happens.
    The same code in a windows application works flawlessly.

    Using a Timer and using the above mentioned class for multiple email-sending did not work.

or Sign Up to reply!