C#笔记7——发送电子邮件C#笔记8——多功能电子邮件发送程序实例

C#笔记7——发送电子邮件

      最近用C#测试了一下发邮件功能,用QQ邮件服务器发送邮件,亲测代码如下!

//for send mail
using System.Net.Mail;
using System.Net;
using System.Threading;
namespace MyHelper

#region send mail
        //参数说明:发件人地址,收件人地址,发件人邮箱密码,邮件主题,邮件内容
        public static void send_email(string email_sender_addr, string email_receiver_addr, string email_sender_pwd, string email_subject, string email_content)
        {
            //使用QQ邮件服务器发送邮件
            SmtpClient smtp = new SmtpClient();
            smtp.EnableSsl = true;
            smtp.UseDefaultCredentials = false;
            smtp.DeliveryMethod = SmtpDeliveryMethod.Network;//指定电子邮件发送方式
            smtp.Host = "smtp.qq.com";//指定SMTP服务器
            smtp.Credentials = new NetworkCredential(email_sender_addr, email_sender_pwd);//发件人邮箱地址和密码

            #region 邮件内容
            MailMessage MyMail = new MailMessage(email_sender_addr, email_receiver_addr);//发件人和收件人
            /*  
            MailMessage MyMail = new MailMessage();
            MyMail.From = new MailAddress("[email protected]");
            MyMail.To.Add(new MailAddress(email_addr));
            以上等价于MailMessage MyMail = new MailMessage(email_sender_addr,email_receiver_addr);
            */
            MyMail.Subject = email_subject;
            MyMail.SubjectEncoding = Encoding.UTF8;

            MyMail.Body = email_content;
            MyMail.BodyEncoding = Encoding.UTF8;
            MyMail.IsBodyHtml = true;
            MyMail.Priority = MailPriority.Low;
            #endregion

            smtp.Send(MyMail);
        }
        #endregion

利用QQ邮箱实现多功能发送邮件的实例可以参考以下文章:

C#笔记8——多功能电子邮件发送程序实例

http://download.csdn.net/download/u011127242/9714085

你可能感兴趣的:(C#)