如何将动态创建的Pdf文档作为附件发送到电子邮件中 [英] how to send dynamic created Pdf document as attachment in email

查看:117
本文介绍了如何将动态创建的Pdf文档作为附件发送到电子邮件中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我找到了创建pdf文件的文章

http://www.aspdotnet-suresh.com/2013/05/aspnet-export-webpage-with-images-to.html [ http://csharpdotnetfreak.blogspot.com/2009/10/send- email-with-attachment-in-aspnet.html [ ^ ]

我也找到这篇文章.
http://www.aspdotnet-suresh. com/2012/09/how-to-send-gridview-in-email-body-in.html [




i find out an article to create pdf file

http://www.aspdotnet-suresh.com/2013/05/aspnet-export-webpage-with-images-to.html[^]


also i find an article to send email as smtp mailing in asp.net c#

http://csharpdotnetfreak.blogspot.com/2009/10/send-email-with-attachment-in-aspnet.html[^]

i also find this article also..
http://www.aspdotnet-suresh.com/2012/09/how-to-send-gridview-in-email-body-in.html[^]


i need to send the dynamically generated pdf as attach file and send to specified email address.

推荐答案

好吧,这很简单.

  • 通过MemoryStream将pdf放入管道
Ok, that''s simple.

  • Pipe the pdf through a MemoryStream
MemoryStream ms = new MemoryStream();

  • 将pdf写入MemoryStream

  • Write the pdf to the MemoryStream

    Document doc = new Document(PageSize.A4, 10f, 10f, 100f, 0.0f);
    //require custom parsers? add here.
    PdfWriter writer = PdfWriter.GetInstance(doc, ms);
    doc.Open(); //open doc for editing
    
    //do layout
    //doc.Add(new Paragraph("First Paragraph"));
    //doc.Add(new Paragraph("Second Paragraph"));
    
    writer.CloseStream = false; //important
    doc.Close(); //build the doc.
    
    memoryStream.Position = 0; //reset stream... important

  • 添加流作为邮件正文的附件!

  • Add the stream as attachment to the mail body!

    mail.Attachments.Add(new Attachment(ms, "filename.pdf"));

  • 发送!

  • Send it!

    smtp.Send(mail);



  • 请参阅此链接

    http://www.aspsnippets.com/Articles/Generate-Create-PDF-and-send-as-email-attachment-in-ASPNet.aspx
    Pls Refer this Link

    http://www.aspsnippets.com/Articles/Generate-Create-PDF-and-send-as-email-attachment-in-ASPNet.aspx


    这篇关于如何将动态创建的Pdf文档作为附件发送到电子邮件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆