繁体   English   中英

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

[英]add multiple selected dates of calendar in mail body wpf c#

在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格式添加所需的正文...?

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

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);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM