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

代码如下:

 

        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邮箱发送,因为新注册的邮箱网易限制了这个功能 。

 

转载于:https://www.cnblogs.com/lthxk-yl/p/4380094.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值