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 CreateMessageWi thAttachment()
{
MailMessage message = new MailMessage();
....
client = new SmtpClient(var. hostName, var.portNo);
client.SendComp leted += new SendCompletedEv entHandler
(SendCompletedC allback);
string userState = "test message1";
client.SendAsyn c(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.Mai l.SmtpException : Failure sending mail. --->
System.ObjectDi sposedException : Cannot access a closed file.".
public static void SendCompletedCa llback(object sender,
AsyncCompletedE ventArgs e)
{
if (e.Error != null)
{
Logger.Write(St ring.Format("Pr ocessed: {0}", e.Error.ToStrin g()));
}
else
{
File.Delete(sAt t.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 CreateMessageWi thAttachment()
{
MailMessage message = new MailMessage();
....
client = new SmtpClient(var. hostName, var.portNo);
client.SendComp leted += new SendCompletedEv entHandler
(SendCompletedC allback);
string userState = "test message1";
client.SendAsyn c(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.Mai l.SmtpException : Failure sending mail. --->
System.ObjectDi sposedException : Cannot access a closed file.".
public static void SendCompletedCa llback(object sender,
AsyncCompletedE ventArgs e)
{
if (e.Error != null)
{
Logger.Write(St ring.Format("Pr ocessed: {0}", e.Error.ToStrin g()));
}
else
{
File.Delete(sAt t.Value);
}
}
Thanks in advance
regards,
Andrew
Comment