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 attachment_url = "http://sitename/biblio/file.docx";
byte[] data = oWebClient.DownloadData(attachment_url);
MemoryStream oMemoryStream = new MemoryStream(data);
string filename_attachment = "filename.docx";
mailMessage.Attachments.Add(new System.Net.Mail.
Attachment(oMemoryStream, filename_attachment, MediaTypeNames.Text.Plain));
SmtpClient oSmtpClient = new SmtpClient(smtpServer);
oSmtpClient.Send(mailMessage);
Если необходимо отправить письмо с пометкой важно, то мы просто добавляем:
mailMessage.Priority = MailPriority.High;
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 attachment_url = "http://sitename/biblio/file.docx";
byte[] data = oWebClient.DownloadData(attachment_url);
MemoryStream oMemoryStream = new MemoryStream(data);
string filename_attachment = "filename.docx";
mailMessage.Attachments.Add(new System.Net.Mail.
Attachment(oMemoryStream, filename_attachment, MediaTypeNames.Text.Plain));
SmtpClient oSmtpClient = new SmtpClient(smtpServer);
oSmtpClient.Send(mailMessage);
Если необходимо отправить письмо с пометкой важно, то мы просто добавляем:
mailMessage.Priority = MailPriority.High;
Комментариев нет:
Отправить комментарий