• 用.NET提供的Mail来发邮件


     首先添加:using System.Net.Mail;

     代码如下,具体自己处理,以符合你的需求:

      public static bool SendMail(string subject, string body)
       {
                bool result = false;
                try
                {

                        List<string> toMailList =new List<string>(){

                        {"sping@sina.com"},

                        {"springyang@sina.com"}

                        };

                        if (toMailList.Count > 0)
                        {
                            MailMessage mail = new MailMessage();
                            foreach (string address in toMailList)
                            {
                                mail.To.Add(new MailAddress(address));
                            }
                            mail.From = new MailAddress("sping1@sina.com");
                            mail.Subject = subject;
                            mail.Body = body;
                            mail.BodyEncoding = System.Text.Encoding.UTF8;
                            mail.IsBodyHtml = false;
                            SmtpClient client = new SmtpClient();
                            client.Host = 25;
                            client.Port = Convert.ToInt32("8080");
                            client.EnableSsl = True;
                            client.Send(mail);
                            result = true;
                        }
                   
                }
                catch (Exception ex)
                {
               
                }
                return result;
            }

  • 相关阅读:
    链接数据库
    Ajax 密码验证
    for循环 打印菱形 空 和 实
    for 循环 正方形
    面向对象
    用正则表达式 匹配手机号码
    正则表达式
    js 中 == 和=== 有什么区别?
    js 删除
    封装函数增删改查
  • 原文地址:https://www.cnblogs.com/springyangwc/p/1961274.html
Copyright © 2020-2023  润新知