Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET C#4.0
Hai all,
 
How to send a mail with an attachemnt in asp.net c#..the attachmnet is a pdf and its created at the time of sening mail.pls help me..
 
Thanks n Advnce
Aatif Ali-Bangalore
Posted 12-Jun-13 3:00am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

  Permalink  
Comments
Aatif Ali from Bangalore at 13-Jun-13 1:01am
   
hai frnd,i want to send pdf as attachment,this pdf is created just before sending the mail using the following code..
 
string src = string.Empty;
string AbsolutePath = string.Empty;
_Filter.Clear();
_Filter.Add("Id",hdnCertificateId.Value);
_CertificatesEntityCollection = CertificatesManager.SelectFiltered(_Filter);
 
ScriptManager.RegisterStartupScript(this, typeof(string), "script123", "AsPdf()", true);
Response.Clear();
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "application/pdf";
//Response.AddHeader("content-disposition", "attachment;filename=" + _CertificatesEntityCollection.First().Name + ".pdf");
Response.AddHeader("Content-Disposition", "attachment; filename=\"" + _CertificatesEntityCollection.First().Name + "\"");
 

 
Response.Cache.SetCacheability(HttpCacheability.NoCache);
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
 
pnlCertificate.RenderControl(hw);
pnlCertificate.Style.Add("border", "2px solid black");
pnlCertificate.Style.Add("margin-top", "60px");
pnlCertificate.Style.Add("text-align", "justify");

src = sw.ToString();
AbsolutePath = HttpContext.Current.Request.Url.Scheme + "://" + HttpContext.Current.Request.Url.Authority + HttpContext.Current.Request.ApplicationPath;
src = src.Replace("img src=\"/", string.Format("img src=\"{0}", AbsolutePath));
StringReader sr = new StringReader(src);
//Document pdfDoc = new Document(PageSize.A4_LANDSCAPE, 20f, 10f, 50f, 0f);
Document pdfDoc = new Document();
pdfDoc.SetPageSize(iTextSharp.text.PageSize.A4.Rotate());

HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
pdfDoc.Open();
htmlparser.Parse(sr);
pdfDoc.Close();
Response.Write(pdfDoc);
Response.End();

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

  Print Answers RSS
0 OriginalGriff 587
1 Sergey Alexandrovich Kryukov 479
2 Maciej Los 305
3 Mathew Soji 195
4 BillWoodruff 170
0 OriginalGriff 7,356
1 Sergey Alexandrovich Kryukov 6,777
2 DamithSL 5,461
3 Manas Bhardwaj 4,916
4 Maciej Los 4,475


Advertise | Privacy | Mobile
Web04 | 2.8.1411023.1 | Last Updated 12 Jun 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100