M
mirror
Hi.
I'm trying to send an email with attachment with System.Web.Mail
When SMTP server I use is down (or I use a non-existing smtp server)
smtp.send() raises a exception
After that I want to delete the attachment I used.
The problem is that (from what I understand) Windows marks the file
as "to be deleted" and it deletes it only when i close my App.
an example of what I am doing is the following:
private void button1_Click(object sender, System.EventArgs e)
{
SmtpMail.SmtpServer = "localhost";
MailMessage m = new MailMessage();
m.From = "(e-mail address removed)";
m.To ="(e-mail address removed)";
m.Attachments.Add(new MailAttachment("c:\\xx.txt"));
try
{
SmtpMail.Send(m);
}
catch(Exception x)
{
MessageBox.Show(x.Message);
}
try
{
System.IO.File.Delete("c:\\xx.txt");
}
catch(Exception x)
{
MessageBox.Show(x.Message);
}
}
I want the file to be deleted immediately after Smtp.Send() without
closing my App.
Is this possible?
I'm trying to send an email with attachment with System.Web.Mail
When SMTP server I use is down (or I use a non-existing smtp server)
smtp.send() raises a exception
After that I want to delete the attachment I used.
The problem is that (from what I understand) Windows marks the file
as "to be deleted" and it deletes it only when i close my App.
an example of what I am doing is the following:
private void button1_Click(object sender, System.EventArgs e)
{
SmtpMail.SmtpServer = "localhost";
MailMessage m = new MailMessage();
m.From = "(e-mail address removed)";
m.To ="(e-mail address removed)";
m.Attachments.Add(new MailAttachment("c:\\xx.txt"));
try
{
SmtpMail.Send(m);
}
catch(Exception x)
{
MessageBox.Show(x.Message);
}
try
{
System.IO.File.Delete("c:\\xx.txt");
}
catch(Exception x)
{
MessageBox.Show(x.Message);
}
}
I want the file to be deleted immediately after Smtp.Send() without
closing my App.
Is this possible?