пятница, 17 февраля 2012 г.

Отправить письмо с вложением

string smtpServer = SPAdministrationWebApplication.Local.OutboundMailServiceInstance.Server.Address;
string smtpFrom = SPAdministrationWebApplication.Local.OutboundMailSenderAddress;

MailAddress fromAdress = new MailAddress(from);
MailAddress toAdress = new MailAddress(to);
MailMessage mailMessage = new MailMessage(fromAdress, toAdress);
mailMessage.Subject = title;
mailMessage.Body = message;
mailMessage.IsBodyHtml = true;

WebClient oWebClient = new WebClient();
oWebClient.Credentials = CredentialCache.DefaultNetworkCredentials;

string filename_attachment = "filename.docx";
string attachment_url = "http://<path>/file.docx";

byte[] data = oWebClient.DownloadData(attachment_url);
 MemoryStream oMemoryStream = new MemoryStream(data);
 mailMessage.Attachments.Add(new System.Net.Mail.
     Attachment(oMemoryStream, filename_attachment, MediaTypeNames.Text.Plain));
 SmtpClient oSmtpClient = new SmtpClient(smtpServer);
oSmtpClient.Send(mailMessage);

Комментариев нет:

Отправить комментарий