Tuesday, December 14, 2010

Sending attachments with SMTP Client

condition is ... Generate a file, sent as an attachment using the SMTP client, and then delete the file generated.

I have created files in order.
I have implemented SMTP client using a fine.

The first attempt error - file in use when trying to delete after sending e-mail ...

message.Attachments.Add (new System.Net.Mail.Attachment (FILEPATH "));
smtp.Send (message);

... OK, so send some reason are still using the files. I just removed another load of nearly posted the text as I understood the answer.
Which is basically ...

Streams Collection = New Collection ();
foreach (string filename in filenames)
System.IO.FileInfo Fileinfo = new System.IO.FileInfo (filename);
flow stream = new MemoryStream (File.ReadAllBytes (filename));
message. Attachments. Add (new System.Net.Mail.Attachment (stream, fileInfo.Name, null));
streams.Add (stream);}
smtp.Send (message);
foreach (stream flow in streams)
stream.Close ();

No comments :

Post a Comment