Email not working in console app (ServiceApplication)

I am trying to send email from console app (ServiceApplication). i am using same code as below which works in my desktop app perfectly but not working from console app.

Socket=new SMTPSecureSocket
Socket.Address =Host //“smtp.gmail.com
Socket.Username =SysEmail //Sender email
Socket.Password = Password //Sender email password
Socket.Port =587

dim EMails() as String

Dim email as New EmailMessage
email.FromAddress =SysEmail //Sender email
email.Subject =“Test From Me”
email.BodyPlainText = “Hello, This is Test Email”

email.AddRecipient(Trim( Receiver)) //Receiver email

Dim file1 as New EmailAttachment

file1.LoadFromFile( GetfolderItem(app.file.NativePath) )

email.Attachments.Append(file1)

Socket.Messages.Append(email)

Socket.Connect
if (Socket.IsConnected) then
str=“1”
else
str=“0”
end if

Socket.SendMail //Send Email

i have above code in a method which i am calling from Timer’s Action event.

My app.Run code is as below

call Daemonize
dim t1 as new CustomTimer
t1.Period=60000
t1.Mode=Timer.ModeMultiple
t1.Enabled=true

do
app.DoEvents 30000 // 60000’ 300000
loop

socket is a property of a class, so it lives long enough?

Thanks Christian for your reply.

i have set interval to 30 seconds for service.

Can you please tell me i can find if socket lives long ?

Did you fill the events for the socket?
like MailSent, MessageSent or error events.
So you notice what happens.

i was getting Time out error.

so i used MBS plugin to send email, it is working now.

Thank you.

1 Like

Always a pleasure to provide an alternative way to get the job done.

30 seconds is way too long for your event loop. The socket will just hang. DoEvents is the mechanism that causes the socket to do it’s work. You’re just starving it.