zoukankan      html  css  js  c++  java
  • 邮件发送

     public class SendMail
        {
            /// <summary>
            /// 发送邮件 WebConfig需配置AppSeting 参数SMTP,EMAIL,EPASS
            /// </summary>
            /// <param name="SendTo">收件人,多个用逗号隔开</param>
            /// <param name="MailTitle">邮件标题</param>
            /// <param name="MailBody">邮件内容,自行Server.HtmlEncode处理</param>
            /// <returns></returns>
            public static bool SendUserMail(string SendTo, string MailTitle, string MailBody)
            {
                bool strResult = false;
                try
                {
                    string smtp = GetConfigAppValue("SMTP");
                    string from = GetConfigAppValue("EMAIL");
                    string fromPass =GetConfigAppValue("EPASS");
                    System.Net.Mail.SmtpClient client = new SmtpClient(smtp);
                    client.Credentials = new System.Net.NetworkCredential(from, fromPass);
                    client.Timeout = 10000;
                    client.EnableSsl = false;
    
                    System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(from, SendTo, MailTitle, MailBody);
                    message.SubjectEncoding = System.Text.Encoding.GetEncoding("GB2312");
                    message.BodyEncoding = System.Text.Encoding.GetEncoding("GB2312");
                    message.IsBodyHtml = true;
                    client.Send(message);
                    strResult = true;
                }
                catch(Exception ex)
                {
                    throw ex;
                }
                return strResult;
            }
    
            /// <summary>
            /// 获取 appSeting中的指定键的键值
            /// </summary>
            /// <param name="strKey"></param>
            /// <returns></returns>
            public static string GetConfigAppValue(string strKey)
            {
                return ConfigurationManager.AppSettings[strKey].ToString();
            }
        }
  • 相关阅读:
    c++ set unordered_set区别
    LeetCode 213. 打家劫舍 II
    LeetCode 152. 乘积最大子序列
    [HAOI 2012] 外星人
    [HAOI 2016] 找相同字符
    [ZJOI2007] 仓库建设
    [SCOI 2016] 美味
    [BZOJ 2127] Happiness
    [NOI2009] 植物大战僵尸
    [SDOI 2016] 数字配对
  • 原文地址:https://www.cnblogs.com/LJP-JumpAndFly/p/12009808.html
Copyright © 2011-2022 走看看