如何在C#.net中创建动态电子邮件正文。 [英] How to Create Dynamic Email-Body in C#.net.

查看:141
本文介绍了如何在C#.net中创建动态电子邮件正文。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好伙计们,





我面临以下与Email-Body相关的问题,



我想动态创建Email-Body而不是静态,

我的场景是,

我想将一些记录发送给另一个人,即十大记录。

和我从数据库中检索记录但是在DB中只有5条记录然后在模板中它只替换5条记录和其他5条显示模板硬编码值,

所以我想避免这些事情,



当我的记录为5时,我的模板将在数据库记录中决定然后它将填写5个电子邮件正文记录,如果10然后10记录表。



请建议我在这种情况下做什么。

解决方案

< blockquote>您可以从代码中完全生成HTML表格标签。遍历记录并继续在

标记中添加数据。



您可以使用StringBuilder。



如果桌面上方和下方有更多内容。我建议你创建一个html模板文件并放入一些像[Table]这样的Key元素并使用IO操作来读取文件并将[Table]文本替换为dynamicaly生成的html表文本,然后将完整的html作为电子邮件发送(通过设置HTML邮件正文)


您可以遍历数据表并使用StringBuilder [ ^ ]动态创建电子邮件正文。

您可以参考 datatable-foreach Loop [ ^ ]有关如何遍历DataTable中所有元素的信息


hello Guys,


I am facing below problem related to Email-Body,

I want to create Email-Body dynamically not static,
my scenario is,
I want to send some records to another person,i.e. Top 10 records.
and i an retrieving records from database but IF in DB there is present only 5 records then in Template it is replacing only 5 records and other 5 display templates hardcoded value,
so i want to avoid this things,

My templated will be decided on Database records when my record is 5 then it will fill in email body with 5 records and if 10 then 10 record table.

Please suggest me what i do in that case.

解决方案

You can generate HTML Table Tag completely from the code. Traverse through the records and keep adding tags whith data in
tag.

You can use StringBuilder for this.

If there is much more content above and below the table. I suggest u to create a html template file and put some Key element like [Table] and use the IO operations to read the file and replace [Table] text to dynamicaly generated html table text and then send the complete html as email (by setting HTML mail body)


You can loop through the datatable and use StringBuilder[^] to dynamically create the email body.
You can refer datatable-foreach Loop[^] for information on how to loop through all the elements in the DataTable


这篇关于如何在C#.net中创建动态电子邮件正文。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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