Last post Nov 14, 2014 03:24 AM by smirnov
Nov 12, 2014 02:31 AM|ImpossibleIsNothing|LINK
I currently have the code to create a Pdf file through iTextSharp. What I want to do is to create a button when pressed to automatically send this PDF file to the email address specified by the user (i.e. enter an email address to a textbox and send the
PDF file automatically to that email address).
Which is the best way to do this?
I am using C#.
Nov 12, 2014 02:44 AM|smirnov|LINK
To send email, read http://www.aspnettutorials.com/tutorials/email/email-attach-aspnet2-csharp/
Attachment attachFile = new Attachment("path to your pdf file");
Nov 14, 2014 02:09 AM|ImpossibleIsNothing|LINK
Thank you for your e-mail.
I appreciate your reply as it really helped me.
However, I would like not to save the pdf on the server side before sending the attachment, but directly send it from the client side.
As my code is now, the pdf is generated on the client client side and not stored on server's side
Thanks again, I appreciate your response
Nov 14, 2014 03:24 AM|smirnov|LINK
var doc = new Document();
MemoryStream memoryStream = new MemoryStream();
PdfWriter writer = PdfWriter.GetInstance(doc, memoryStream);
doc.Add(new Paragraph("First Paragraph"));
doc.Add(new Paragraph("Second Paragraph"));
//Keeps the memoryStream object open when closing the Document (doc)
writer.CloseStream = false;
//Moves the pointer to the beginning of the stream. Without this
//line an empty file is generated and attached to the email.
memoryStream.Position = 0;
MailMessage mm = new MailMessage("firstname.lastname@example.org",
Subject = "subject",
IsBodyHtml = true,
Body = "body"
mm.Attachments.Add(new Attachment(memoryStream, "filename.pdf"));
SmtpClient smtp = new SmtpClient
Host = "smtp.gmail.com",
Port = 587,
EnableSsl = true,
Credentials = new NetworkCredential("email@example.com",