zoukankan      html  css  js  c++  java
  • 用.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;
            }

  • 相关阅读:
    implement the bucket sort and some analysis
    冪運匴
    polynomial multiplication
    WinRAR(WinZip)压缩与解压实现(C#版Window平台)
    Windows 窗体计时器事件,则不引发在 Windows 服务
    VS 2008智能提示是英文的怎么改成中文的?
    C#_SQL数据访问帮助类
    C#_DllImport用法和路径问题
    Office2003/2007/2010强力卸载工具下载
    Windows_装的是2008R2系统,在电脑属性里显示内存12G(可用4G)
  • 原文地址:https://www.cnblogs.com/springyangwc/p/1961274.html
Copyright © 2011-2022 走看看