c# - 在电子邮件的列表中显示项目
问题描述
我编写了一个匹配算法,无论出于何种原因,没有匹配的学生都存储在全局变量的列表中。我是这个列表,要作为电子邮件发送给管理员。我需要帮助来阅读列表中的项目并将它们添加到电子邮件中。
全局变量是:
public static List<string> V_result_rest_student = new List<string>();
public static List<string> result_rest_student
{
get { return V_result_rest_student; }
set { V_result_rest_student = value; }
}
调用电子邮件服务的函数:
if(General.result_rest_student.Count > 0)
{
_emailService.SendStatusEMail(General.result_rest_student, User, EmailType.Unsorted_Students);
}
发送电子邮件的程序:
public void SendStatusEMail(List<string> list, User User, EmailType type)
{
MailAddress from = new MailAddress(config.mailSender, "Matching-Team");
MailAddress to = new MailAddress("matching@gmail.com");
MailMessage mail = new MailMessage(from, to);
mail.IsBodyHtml = true;
mail.Bcc.Add(from);
SmtpClient client = new SmtpClient();
client.Port = port;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
string header = string.Format(config.header);
string footer = config.footer;
if (list == null)
{
return;
}
string msg = "";
switch (type)
{
case EmailType.Unsorted_Student:
foreach (var item in list)
{
msg = item;
}
break;
case EmailType.Finished_List:
msg = config.Finished_List;
break;
default:
break;
}
msg = string.Format(msg);
mail.Subject = string.Format(config.mailSubject, "List of Unsorted Students");
mail.Body = header + msg + footer;
try
{
client.Send(mail);
}
catch (Exception ex)
{
Console.WriteLine("<Error> EMail Couldn't be sent.",
ex.ToString());
}
}
我需要未分类学生的 UserId 作为电子邮件发送给管理员。我正在使用 C#(.Net 框架)
解决方案
我认为您只需要添加一个 var 即可将您的列表转换为字符串。尝试这个:
var result = String.Join("</BR>", General.result_rest_student);
</BR>
如果您希望所有内容都在一行上,则“ ”可以替换为“,”。
推荐阅读
- cuda - float3 可以享受 CUDA 内存合并吗?
- javascript - 使用 javascript 确认时,Asp.net requiredfieldvalidator 停止工作
- html - 缩放和变换原点后网页没有覆盖整个屏幕高度
- arrays - 如何检查我的 Object PersistantCollection 中是否存在值?
- angular - 角度:为什么值更改(使用渲染器2)不会触发绑定到该的事件
- typescript - 共享自定义 NestJS 模块给出“不是当前处理模块的一部分”错误
- python - 子类未在 Python 2.x 中初始化父类
- python - 直方图给出了概率密度函数的奇怪值
- java - 如何在日志文本上将 OrderId 显示为 Log4j 模式布局
- android - 改造 - 处理刷新令牌过期