SMTPSocket from console app

Hi, I am trying to send an email from a console app. I need to use some of the SMTPSocket events. In the past I have been able to put my code in via the Window Contol which you do not have in a console app.

Insert a class into the project and make it’s super SMTP Socket. Then you can add events just the same way as in desktop.

In the Run event, instanciate the class as for instance :

Dim SMTP as new mySocket

Alternatively, add a SMTP as SMTPSocket property to App, and use Addhandler for the events.

In both cases, make sure not to quit the run event before all mail has been sent.

Michel, Many thanks for your prompt reply. I had added a class with its super class as SMTPSocket, but I had not double clicked it to get the event handlers up !!
Thanks again
David

[quote=255259:@David Simpson]Michel, Many thanks for your prompt reply. I had added a class with its super class as SMTPSocket, but I had not double clicked it to get the event handlers up !!
Thanks again[/quote]

You are welcome. One last detail, though : since the events are attached to the class and not the instance, if you need to get or set properties on app, make sure to prefix them, such as App.Message and not simply Message.

The purpose of this extra bit of code in my console app is to send an email to inform me that it crashed. Which is the best way to make sure that the run event does not terminate before the asynchronous email has been sent?

You should implement UnhandledException and probably do the sending there with a short report of the error encountered and maybe the stack. Make sure to terminate the code by a loop with DoEvents into it that waits until the MailSent event has taken place.

If it crashes for good I doubt you will have time to send anything.