动态生成pdf文件并将电子邮件作为附件发送。 [英] Dynamically generate pdf file and Send an Email as a attachment.

查看:219
本文介绍了动态生成pdf文件并将电子邮件作为附件发送。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在运行时动态生成PDF我们自己的设计并将邮件作为附件生成并发送该PDF文件。



请告诉我解决方案。



在此先感谢

Jagan Mohana Rao

I need to generate dynamically PDF our own design in run time and mail as attachment and send that PDF.

Please tell me the solution.

Thanks in Advance
Jagan Mohana Rao

推荐答案

这是最常见的问题,谷歌创建pdf文件c#获取数千个现有答案。
This is the most frequently asked question, google "create pdf file c#" for thousands of existing answers.


这是一组可以使用的PDF库参考: http://csharp-source.net/open-source/pdf-libraries



这可能是最常用的库: iTextSharp,一个.NET PDF库SourceForge.net [ ^ ]。



现在,关于邮件附件。这是一项非常令人困惑的工作。事实上,没有任何附加。电子邮件是带有可选部件的纯文本数据块。每个部分都可以拥有自己的内容类型内容配置。请参阅:

MailMessage类(System.Net.Mail) [ ^ ],

MailMessage.Attachments Property(System.Net.Mail) [ ^ ],

AttachmentBase .ContentType属性(System.Net.Mail) [ ^ ],

Attachment.ContentDisposition Property(System.Net.Mail) [< a href =https://msdn.microsoft.com/en-us/library/system.net.mail.attachment.contentdisposition%28v=vs.110%29.aspx\"target =_ blanktitle =新窗口> ^ ],

ContentDisposition类(System.Net.Mime) [ ^ ]。



内容类型得到维护,由IANA标准化,在此处:

媒体类型

媒体类型 Text )。



如您所见,您需要application / pdf。该内容的数据(与大多数其他情况一样)应以base64格式表示( Base64 - 维基百科,免费百科全书 [ ^ ])。至于 ContentDisposition ,它显示了邮件消息查看器如何显示该部件。它可以在单一流程中呈现,主要内容是商品下载,因此您有以下选项:

DispositionTypeNames.Inline Field(System.Net.Mime) [ ^ ],
DispositionTypeNames.Attachment字段(System.Net.Mime) [ ^ ]。



使用PDF,你当然需要姓氏值 ContextDisposition System.Net.Mime.DispositionTypeNames.Attachment



最后,s结束邮件。在.NET FCL中,支持SMTP: SmtpClient类(System.Net.Mail) [ ^ ]。



对于其他客户端协议,您可以轻松找到第三方解决方案,但SMTP通常就够了。



-SA
This is a set of references to PDF libraries you can use: http://csharp-source.net/open-source/pdf-libraries.

This is probably the most used library: iTextSharp, a .NET PDF library | SourceForge.net[^].

Now, about mail "attachment". This is a very confusing work. In fact, nothing is "attached". E-mail is a pure-text block of data with optional "parts". Each part can have it's own content type and content disposition. Please see:
MailMessage Class (System.Net.Mail)[^],
MailMessage.Attachments Property (System.Net.Mail)[^],
AttachmentBase.ContentType Property (System.Net.Mail)[^],
Attachment.ContentDisposition Property (System.Net.Mail)[^],
ContentDisposition Class (System.Net.Mime)[^].

Content types are maintained and standardized by IANA, here:
Media Types,
Media Types (Text).

As you can see, you need "application/pdf". The data for this content (as with most other cases), should be represented in base64 form (Base64 - Wikipedia, the free encyclopedia[^]). As to ContentDisposition, it shows the mail message viewer how to display the part. It can be rendered in the single flow with main content of offer downloading, hence you have these options:
DispositionTypeNames.Inline Field (System.Net.Mime)[^],
DispositionTypeNames.Attachment Field (System.Net.Mime)[^].

With PDF, you certainly need the last name value for ContextDisposition, System.Net.Mime.DispositionTypeNames.Attachment.

Finally, sending mail. In .NET FCL, SMTP is supported: SmtpClient Class (System.Net.Mail)[^].

For other client protocols, you can easily find 3rd-party solutions, but SMTP is usually enough.

—SA


这篇关于动态生成pdf文件并将电子邮件作为附件发送。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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