itextsharp를 사용하여 pdf를 만듭니다. pdf는 정상적으로 생성되어 사용자가 컴퓨터에 파일을 쉽게 저장할 수 있도록 브라우저에 게시합니다. 지금 나는 생성 된 pdf가 전자 우편으로 자동으로 그것을 보내고 싶다. 컨텍스트에 게시하기 전에 의사를 변환하려고 시도했지만 전자 메일에 첨부하지만 성공하지는 못했습니다. 내 코드입니다 : 내가 얻을HttpContext.Current.Response에서 생성 된 전자 메일 첨부 보내기
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ContentType = "application/pdf";
HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=mypdf.pdf");
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
StringWriter stringWriter = new StringWriter();
HtmlTextWriter htmlTextWriter = new HtmlTextWriter(stringWriter);
string imagepath = Server.MapPath(".") + "/assets/myimages/myimage.png";
Document Doc = new Document(PageSize.A4, 10f, 10f, 10f, 10f);
HTMLWorker htmlparser = new HTMLWorker(Doc);
PdfWriter pdfwriter= PdfWriter.GetInstance(Doc, HttpContext.Current.Response.OutputStream);
Doc.Open();
iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(imagepath);
image.ScalePercent(106f,90f);
Doc.Add(image);
//adding elements using itextshart pdf
AddPDf(pdfwriter,Doc);
//to add html in pdf
// htmlparser.Parse(stringReader);
OnEndPage(pdfwriter, Doc);
Doc.Close();
email_send(Doc.ToString());
HttpContext.Current.Response.End();
public void email_send(string filename)
{
MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
mail.From = new MailAddress("[email protected]");
mail.To.Add("[email protected]");
mail.Subject = "Test Mail - 1";
mail.Body = "mail with attachment";
System.Net.Mail.Attachment attachment;
attachment = new System.Net.Mail.Attachment((Server.MapPath(filename.ToString())));
mail.Attachments.Add(attachment);
SmtpServer.Port = 587;
SmtpServer.Credentials = new System.Net.NetworkCredential("[email protected]", "mypass");
SmtpServer.EnableSsl = true;
SmtpServer.Send(mail);
}
오류 : 대신 파일 경로의, 당신의 email_send
방법에 Doc
객체 참조를 전달하는 것이 오류의
Could not find file
{"Could not find file 'C:\\Admin\\iTextSharp.text.Document'.":"C: \\Admin\\iTextSharp.text.Document"}
_ "성공했지만 아무 것도 없습니다"_ - [ask]를 읽고 _does_이 어떻게되는지 설명하십시오. 왜 당신은'Response.End()'를 호출할까요, 그 메소드에 대한 문서를 읽으려고 했습니까? – CodeCaster
내 코드를 편집했습니다. – focus
을 확인하십시오. 이제 Response.End 이후 이메일을 보내지 않으므로 제목을 변경해야합니다. 그러나 문제는 무엇입니까? 이메일이 전송되지 않았습니까? 문서가 첨부되지 않았습니까? –