您的足迹:首页 > 未分类 >C#一个发送邮件的帮助类

C#一个发送邮件的帮助类

using System;

using System.Collections.Generic;

using System.Net.Mail;

using System.Text;

 

namespace Insert

{

    public class SendMailHelper

    {

        #region 常用邮箱发送邮件服务器

        //qq邮箱

        public const string QQSmtpServer = "smtp.qq.com";

        //网易163邮箱

        public const string WYSmtpServer = "smtp.163.net";

        //新浪邮箱

        public const string XLSmtpServer = "smtp.sina.com.cn";

        //谷歌gmail邮箱

        public const string GGSmtpServer = "smtp.gmail.com";

 

        #endregion

 

        #region 发送邮件

 

        /// <summary>

        /// Net 2.0 发送邮件

        /// </summary>

        /// <param name="strSmtpServer">发送邮件服务器</param>

        /// <param name="strFrom">发信人Email</param>

        /// <param name="strFromPass">发信人Email密码</param>

        /// <param name="strTo">收信人Email</param>

        /// <param name="strSubject">邮件主题</param>

        /// <param name="strBody">邮件内容</param>

        public static void Send(string strSmtpServer, string strFrom, string strFromPass, string strTo, string strSubject, string strBody)

        {

            SmtpClient client = new SmtpClient(strSmtpServer);

 

            client.UseDefaultCredentials = false;

            client.Credentials = new System.Net.NetworkCredential(strFrom, strFromPass);

            client.DeliveryMethod = SmtpDeliveryMethod.Network;

 

            Byte[] b = Encoding.Default.GetBytes(strBody);

            strBody = Encoding.GetEncoding("gb2312").GetString(b).ToString();

 

            MailMessage message = new MailMessage(strFrom, strTo, strSubject, strBody);

 

            message.BodyEncoding = Encoding.UTF8;

            message.IsBodyHtml = true;

 

            client.Send(message);

        }

        

        #endregion

    }

}
本博客所有文章如无特别注明均为原创。作者:cc复制或转载请以超链接形式注明转自 我的博客
原文地址《C#一个发送邮件的帮助类

相关推荐

发表评论

路人甲 表情
Ctrl+Enter快速提交

网友评论(0)