首页 > 解决方案 > 在电子邮件的列表中显示项目

问题描述

我编写了一个匹配算法,无论出于何种原因,没有匹配的学生都存储在全局变量的列表中。我是这个列表,要作为电子邮件发送给管理员。我需要帮助来阅读列表中的项目并将它们添加到电子邮件中。

全局变量是:

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 框架)

标签: c#asp.netemail

解决方案


我认为您只需要添加一个 var 即可将您的列表转换为字符串。尝试这个:

var result = String.Join("</BR>", General.result_rest_student);

</BR>如果您希望所有内容都在一行上,则“ ”可以替换为“,”。


推荐阅读