MailMessage attachmentmessage = new MailMessage(); attachmentmessage.From = new MailAddress("administrator@domain.com"); attachmentmessage.To.Add(new MailAddress("test@domain.com")); attachmentmessage.IsBodyHtml = true; attachmentmessage.Body = "this is a test mail"; attachmentmessage.Subject = "for testing";
string url = "http://emiliu:8081/team/testlibrary/Doc1.docx"; SPSite attachmentsite = new SPSite("http://emiliu:8081"); SPWeb attachmentweb = attachmentsite.OpenWeb("/team"); SPFile file = attachmentweb.GetFile(url); attachmentmessage.Attachments.Add(new Attachment(file.OpenBinaryStream(), file.Name));
SmtpClient smtpClient = new SmtpClient("exchangeserver.domain.com"); smtpClient.UseDefaultCredentials = true; smtpClient.Send(attachmentmessage);
Done.