private void SendMailWithAttachment() { string mail_from = "your account"; string mail_to = "whatever@something"; string mail_smtp_server = "smtp.someserver"; MailMessage message = new MailMessage(); MailAddress sender = new MailAddress(mail_from); message.From = sender; message.Subject = "Some text"; message.Body = "Massage"; // attachment FileStream fs = File.OpenRead("destination of the file"); byte[] cv = new byte[fs.Length]; fs.Read(cv, 0, cv.Length); MemoryStream ms = new MemoryStream(cv); Attachment attach = new Attachment(ms, "filename"); message.Attachments.Add(attach); message.To.Add(mail_to); SmtpClient smtp = new SmtpClient(mail_smtp_server); smtp.Send(message); } |
Saturday, April 25, 2009
Sending Mail whit attachment
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment