TEL:150-0382-3679
新闻资讯 News Center
建站知识 / 公司动态
.net.邮件单发和群发

asp.net.邮件单发和群发

注:如果此类和项目分层,请添加引用using System.Web;(引用)才能实现1和2的引用


using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Collections.Generic;
using System.Text;
using System.Web.Util;//////////1引用
using System.Web.Mail;//////////2引用

namespace Bll
{
    public class sendmail  //服务邮箱尽量不要换,需要资格用户才能发送邮件
    {
        protected static string smtp = "企业邮箱";
        protected static string username = "用户名";
        protected static string password = "密码";
        public static bool sendMail(string addressee, string title, string content)
        {
            try
            {
                MailMessage msg = new MailMessage();
                msg.From = username;
                msg.To = addressee;
                msg.Subject = title;
                msg.Body = content;

                msg.Priority = MailPriority.Normal; //设置优先集

                msg.BodyFormat = MailFormat.Html;

                SmtpMail.SmtpServer = smtp;

                msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", 1);
                //cdoBasic 基本验证 gmail使用ssl验证
                //msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpusessl", "No");
                //账号
                msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", username);
                //密码
                msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", password);

                SmtpMail.Send(msg);
                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }
        public static bool sendColonyMail(string[] addresseeList, string title, string content)
        {
            try
            {
                MailMessage msg = new MailMessage();
                msg.From = username;
                string straddressee = "";
                foreach (string addressee in addresseeList)
                {
                    straddressee += ","+addressee;
                }
                msg.To = straddressee.Substring(1, straddressee.Length);
                msg.Subject = title;
                msg.Body = content;

                msg.Priority = MailPriority.Normal; //设置优先集

                msg.BodyFormat = MailFormat.Html;
                
                SmtpMail.SmtpServer = smtp;

                msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", 1);
                //cdoBasic 基本验证 gmail使用ssl验证
              //  msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpusessl", "No");
                //账号
                msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", username);
                //密码
                msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", password);

                SmtpMail.Send(msg);
                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }
    }
}

一站式全网营销,您身边的网络营销顾问,为您一对一私人定制符合您实际需求的网络营销实施方案!
24小时咨询热线:
150-0382-3679