SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

code is developed to attach pdf and send as email. But email received dont contain the pdf format. On click of file, it gives option of "open with". mentioned is code used.... "attach1" is the path of the pdf which is in library. string email = string.Empty; string smtpServer =SPAdministrationWebApplication.Local.OutboundMailServiceInstance.Server.Address; string smtpFrom = SPAdministrationWebApplication.Local.OutboundMailSenderAddress; MemoryStream memoryStreamOfFile1 = null;

data1 = webClient.DownloadData(attach1); memoryStreamOfFile1 = new MemoryStream(data1); mail.Attachments.Add(new System.Net.Mail.Attachment(memoryStreamOfFile1, empID,"application/pdf")); smtpClient.Send(mail);

share|improve this question

Plz try below code..

SmtpClient smtpClient = new SmtpClient();
smtpClient.Host = SPContext.Current.Site.WebApplication.OutboundMailServiceInstance.Server.Address;
string fromAddress = SPContext.Current.Site.WebApplication.OutboundMailReplyToAddress;
List<Attachment> attachments = new List<Attachment>();
string mimeType = "application/pdf";
System.IO.Stream stream = yourpdfSPFileObject.OpenBinaryStream();
Attachment attach = new Attachment(stream, mimeType);
attach.Name = file.Name;
MailMessage mailMessage = new MailMessage(fromAddress, emailAddress, Subject, Body);

                if (!String.IsNullOrEmpty(Cc))
                    MailAddress CCAddress = new MailAddress(Cc);
                if (!String.IsNullOrEmpty(Bcc))
                    MailAddress BCCAddress = new MailAddress(Bcc);
                if (attachments.Count > 0)
                    foreach (Attachment attachment in attachments)
                mailMessage.IsBodyHtml = IsBodyHtml;

Hope it helps..

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.