码迷,mamicode.com
首页 > Windows程序 > 详细

c# winform 程序用126邮箱发邮件

时间:2015-03-31 10:36:25      阅读:144      评论:0      收藏:0      [点我收藏+]

标签:

代码如下:

 

        private void button1_Click(object sender, EventArgs e)
        {
            string strTitle = "alert! We have not receive new data from mera over 20 mins";

            try
            {
                SmtpClient client = new SmtpClient("smtp.126.com", 25)
                {
                    Credentials = new NetworkCredential("emailAddress", "password"),
                    EnableSsl = true
                };

                MailAddress from = new MailAddress(@"emailAddress", "senderName");
                MailAddress to = new MailAddress(@"receiverAddress", "ReceiverName");
                MailMessage myMail = new System.Net.Mail.MailMessage(from, to);

                myMail.Subject = strTitle;
                myMail.SubjectEncoding = System.Text.Encoding.UTF8;
                myMail.Body = "";

                myMail.BodyEncoding = System.Text.Encoding.UTF8;
                client.Send(myMail);

            }
            catch (SmtpException ex)
            {
                throw new ApplicationException
                  ("SmtpException has occured: " + ex.Message);
            }
        }  // end of function 


需要注意的是, 要使用注册很久的126邮箱发送,因为新注册的邮箱网易限制了这个功能 。

 

c# winform 程序用126邮箱发邮件

标签:

原文地址:http://www.cnblogs.com/lthxk-yl/p/4380094.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!