A
Andrew
Hi,
I want to delete my email attachment after sending the email. How do I get
around this issue ?
I have set up a method to send email using SMTP.
public bool CreateMessageWithAttachment()
{
MailMessage message = new MailMessage();
....
client = new SmtpClient(var.hostName, var.portNo);
client.SendCompleted += new SendCompletedEventHandler
(SendCompletedCallback);
string userState = "test message1";
client.SendAsync(message, userState);
}
This method is called last after the email is actually sent. I can't put a
Dispose() call in the above as I would get an error
"System.Net.Mail.SmtpException: Failure sending mail. --->
System.ObjectDisposedException: Cannot access a closed file.".
public static void SendCompletedCallback(object sender,
AsyncCompletedEventArgs e)
{
if (e.Error != null)
{
Logger.Write(String.Format("Processed: {0}", e.Error.ToString()));
}
else
{
File.Delete(sAtt.Value);
}
}
Thanks in advance
regards,
Andrew
I want to delete my email attachment after sending the email. How do I get
around this issue ?
I have set up a method to send email using SMTP.
public bool CreateMessageWithAttachment()
{
MailMessage message = new MailMessage();
....
client = new SmtpClient(var.hostName, var.portNo);
client.SendCompleted += new SendCompletedEventHandler
(SendCompletedCallback);
string userState = "test message1";
client.SendAsync(message, userState);
}
This method is called last after the email is actually sent. I can't put a
Dispose() call in the above as I would get an error
"System.Net.Mail.SmtpException: Failure sending mail. --->
System.ObjectDisposedException: Cannot access a closed file.".
public static void SendCompletedCallback(object sender,
AsyncCompletedEventArgs e)
{
if (e.Error != null)
{
Logger.Write(String.Format("Processed: {0}", e.Error.ToString()));
}
else
{
File.Delete(sAtt.Value);
}
}
Thanks in advance
regards,
Andrew