?
Solved

email pdf attachment inline

Posted on 2008-11-17
3
Medium Priority
?
3,687 Views
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);
message.Attachments.Add(inline);
 
client.Host = Session["smtp"].ToString();
client.Port = Convert.ToInt32(Session["port"].ToString());
client.Send(message);

Open in new window

0
Comment
Question by:briffab
  • 2
3 Comments
 
LVL 9

Expert Comment

by:amx
ID: 22975640
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.
0
 

Author Comment

by:briffab
ID: 22976190
so why will an image work with this code but not a pdf?
0
 
LVL 9

Accepted Solution

by:
amx earned 2000 total points
ID: 22976291
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.
0

Featured Post

Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There was an incident about the POP3 issue for the double read receipts and delivery receipts in Exchange 2013.  There was huge research been done and found solution for the duplicate mails. Especially when the user gets  duplicate mails.
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
Loops Section Overview
Screencast - Getting to Know the Pipeline
Suggested Courses

809 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