email pdf attachment inline

Posted on 2008-11-17
Last Modified: 2013-12-17
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

Question by:briffab
    LVL 9

    Expert Comment

    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.

    Author Comment

    so why will an image work with this code but not a pdf?
    LVL 9

    Accepted Solution

    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.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Join & Write a Comment

    Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
    Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now