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 //“
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) )



if (Socket.IsConnected) then
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

app.DoEvents 30000 // 60000’ 300000

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.