码迷,mamicode.com
首页 > Windows程序 > 详细

C#发送邮件

时间:2019-12-08 17:40:09      阅读:95      评论:0      收藏:0      [点我收藏+]

标签:als   time   timesheet   str   connect   end   参考   client   body   

    MailSettings.SMTPServer = Convert.ToString(ConfigurationManager.AppSettings["HostName"]);
    MailMessage Msg = new MailMessage();
    // Sender e-mail address.
    Msg.From = new MailAddress("pqr@gmail.com");
    // Recipient e-mail address.
    Msg.To.Add("abc@gmail.com");
    Msg.CC.Add("zcd@gmail.com");
    Msg.Subject = "Timesheet Payment Instruction updated";
    Msg.IsBodyHtml = true;
    Msg.Body = emailMessage.ToString();
    NetworkCredential loginInfo = new NetworkCredential(Convert.ToString(ConfigurationManager.AppSettings["UserName"]), Convert.ToString(ConfigurationManager.AppSettings["Password"])); // password for connection smtp if u dont have have then pass blank

    SmtpClient smtp = new SmtpClient();
    smtp.UseDefaultCredentials = true;
    smtp.Credentials = loginInfo;
    //smtp.EnableSsl = true;
    //No need for port
    //smtp.Host = ConfigurationManager.AppSettings["HostName"];
    //smtp.Port = int.Parse(ConfigurationManager.AppSettings["PortNumber"]);
     smtp.Send(Msg);

 

参考:https://stackoverflow.com/questions/13506623/smtp-exception-failure-sending-mail

 

C#发送邮件

标签:als   time   timesheet   str   connect   end   参考   client   body   

原文地址:https://www.cnblogs.com/shy1766IT/p/12006129.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!