Dear community.
I have written some simple code, to send en auto generated email, using the System.mail.Net namespace.
It works like a charm, but there is one little problem.
The mail does not get send, untill my whole application is terminated.
Does any of you have a workaround for this?
Here is the code I use (c#):
try
{
MailMessage mail = new MailMessage();
mail.From = new MailAddress("[email protected]");
mail.To.Add("[email protected]");
mail.Subject = "Test test";
mail.Body = "blah blah";
mail.Attachments.Add(new Attachment("c:\\file.txt"));
SmtpClient smtp = new SmtpClient("myserver.mail.com");
smtp.Send(mail);
}
catch (SmtpFailedRecipientsException ex)
{
Console.WriteLine(ex);
}
As I said, everything works, but the mail is not send, untill I terminate the application.
Is there any way to force it to send the mail now?
The reason it is a problem, is both that I want the mail to be sent instantly without the user needing to reboot the application, but also because I want to delete the attachment after the mail has been sent, and when the mail isn't sent, the file is therefore marked as "in use" and can therefore not be deleted.
Best regards
/S