在邮件正文wpfc#中添加日历的多个选定日期

本文关键字:日期 日历 添加 正文 wpfc# | 更新日期: 2023-09-27 18:29:43

在MyCalendar_SelectedDatesChanged()事件中,我在列表框中显示所有多个选定日期。我需要选择所有这些日期并逐行添加到电子邮件正文中。发送邮件代码:

login = new NetworkCredential("wapsatest@gmail.com", "wapsatest123456");
                    client = new SmtpClient("smtp.gmail.com");
                    client.Port = Convert.ToInt32(587);
                    client.EnableSsl = true;
                    client.Credentials = login;
                    msg = new MailMessage { From = new MailAddress("wapsatest" + "smtp.gmail.com".Replace("smtp.", "@"), "nWorks Employee", Encoding.UTF8) };
                    msg.To.Add(new MailAddress("saurabh.pawar@nworks.co"));
                    msg.Subject = "Requested for leave by "+comboboxEmployee.Text;
                    msg.Body = "///////////////List of dates coming from list box name selecteddates";
 msg.BodyEncoding = Encoding.UTF8;
                    msg.IsBodyHtml = true;
                    msg.Priority = MailPriority.Normal;
                    msg.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
                    client.SendCompleted += new SendCompletedEventHandler(SendCompletedCallback);
                    string userstate = "sending.......";
                    client.SendAsync(msg, userstate);

如何在c#wpf中使用html格式添加所需的正文。。。?

在邮件正文wpfc#中添加日历的多个选定日期

请尝试以下可能对您有所帮助的代码。

login = new NetworkCredential("wapsatest@gmail.com", "wapsatest123456");
client = new SmtpClient("smtp.gmail.com");
client.Port = Convert.ToInt32(587);
client.EnableSsl = true;
client.Credentials = login;
msg = new MailMessage { From = new MailAddress("wapsatest" + "smtp.gmail.com".Replace("smtp.", "@"), "nWorks Employee", Encoding.UTF8) };
msg.To.Add(new MailAddress("saurabh.pawar@nworks.co"));
msg.Subject = "Requested for leave by "+comboboxEmployee.Text;
//-------------------Code for your Email body---------------------
string strBody = string.Empty;
int i = 1;
strBody += "///////////////List of dates coming from list box name selecteddates";
strBody += Environment.NewLine;
foreach (var item in lstDate)  // here "lstDate" is name of your list where you store all date.
{
    //strBody += item.ToShortDateString() + Environment.NewLine;
    strBody += "Some text before date".
    strBody += i + ". " + item.ToShortDateString() + " (" + item.DayOfWeek + ")";
    strBody += "Some text after date".
    strBody += "<br/>";
    i++;
}
msg.Body = strBody;
//----------------------------- Over -----------------------------
msg.BodyEncoding = Encoding.UTF8;
msg.IsBodyHtml = true;
msg.Priority = MailPriority.Normal;
msg.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
client.SendCompleted += new SendCompletedEventHandler(SendCompletedCallback);
string userstate = "sending.......";
client.SendAsync(msg, userstate);