Click here to Skip to main content
15,902,636 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
hi,

im doing one quotation project in that when the client fill the quotation and submit the button the details in the filled quotation should be created as pdf and the pdf file should be send through mail as an attachment.here i have created the pdf file.what i need is how to send the created pdf through attachment in mail?

this is my code for creating pdf

Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition",                  "attachment;filename=TestPage.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
this.Page.RenderControl(hw);
StringReader sr = new StringReader(sw.ToString());
Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 100f, 0f);
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
pdfDoc.Open();
htmlparser.Parse(sr);
pdfDoc.Close();
Response.Write(pdfDoc);
Response.End();

plz tell me how to send this pdf file as attach in mail????
Posted
Updated 29-Apr-12 19:03pm
v4

Create quotation in pdf at the time of saving and the mail it in simple way.
You can send mail like this

C#
MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
mail.From = new MailAddress(txtFromEmailID.Text);
mail.To.Add(txtTOEmailID.Text);
mail.Subject = txtSubject.Text;
mail.Attachments.Add(new Attachment("path of your pdf file"));
SmtpServer.Port = 587;
SmtpServer.Credentials = new System.Net.NetworkCredential(txtFromEmailID.Text,txtPassword.Text);
SmtpServer.EnableSsl = true;
SmtpServer.Send(mail);


hope this help you
 
Share this answer
 
v2
Comments
Nelek 14-Apr-12 9:29am    
Added code tags
dineshdena 20-Apr-12 0:35am    
sir,
actually the pdf is generated dinamicaly when the client fill the quotation form in that how we give the pdf path(in client system me cant set the path). :(
plz help me.
Member 12806385 14-Mar-17 8:20am    
Want to sent email without save to folder
Don't know why you popped this question out again. I checked the version differences and it was few grammar changes.

Yet, here you go: Sending an Email in C# with or without attachments: generic routine.[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900