Email not sent in console application

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:

[code]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[/code]

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

Thanks in advance

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

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

[code]EmailSocket.Connect

While 1=1
EmailSocket.Connect
If EmailSocket.IsConnected Then Exit
Wend
[/code]
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.

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

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

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.

Forum for Xojo Programming Language and IDE. Copyright © 2021 Xojo, Inc.