• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3794
  • Last Modified:

email pdf attachment inline

I am trying to send an email with a pdf attached inline with c#. It gets sent but does not appear in the body of the email.
 Can someone help please
MailAddress from = new MailAddress(froma);
MailAddress to = new MailAddress(email);
MailMessage message = new MailMessage(from,to);
SmtpClient client = new SmtpClient();
message.Subject = this.txtSubject.Text;
message.IsBodyHtml = true;
string attachmentPath = pdffile;
System.Net.Mail.Attachment inline = new System.Net.Mail.Attachment(attachmentPath, MediaTypeNames.Application.Pdf);
inline.ContentDisposition.Inline = true;
inline.ContentDisposition.DispositionType = DispositionTypeNames.Inline;
inline.ContentType.MediaType = MediaTypeNames.Application.Pdf;
inline.ContentType.Name = Path.GetFileName(attachmentPath);
client.Host = Session["smtp"].ToString();
client.Port = Convert.ToInt32(Session["port"].ToString());

Open in new window

  • 2
1 Solution
Unfortunately this tends to depend upon the email client being used, its not something you can set programmatically.

In your code you seem to be setting meta data about the attachement but this has no effect on whether this will be displayed in the email body.
briffabAuthor Commented:
so why will an image work with this code but not a pdf?
Because the email client you're using has that capabilty built in.

If you tried to view a pdf in your browser but didn't have the adobe plugin installed you would would be able to see the pdf in the correct format, same thing appies to email clients. Also the email client might see it as a security risk but again this is down which client you use.

Images just happens to be a format which doesn't required a vendor specific tie-in.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now