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

c#基于System.Net.Mail实现发送邮件功能

时间:2017-10-04 19:14:57      阅读:260      评论:0      收藏:0      [点我收藏+]

标签:private   tns   setting   主题   use   void   show   添加引用   eve   

1.添加引用

  using System.Net.Mail;

2.发送邮件实现代码

        private void btnsend_Click(object sender, EventArgs e)
        {
            try
            {
                var senduser = ConfigurationManager.AppSettings["senduser"];// "test@qq.com";
                var sendpwd = ConfigurationManager.AppSettings["sendpwd"];// "test";

                var receiver = this.txtreceiver.Text;
                var sendmsg = this.txtsendmsg.Text;

                var message = new MailMessage();
                var fromddress = new MailAddress(senduser);
                message.From = fromddress;

                message.To.Add(receiver);//接收方
                message.CC.Add(receiver);//抄送方
                message.Subject = "test";//主题
                message.Body = sendmsg;//内容
                message.Attachments.Add(new Attachment("test.txt"));//附件

                SmtpClient client = new SmtpClient("smtp.qq.com", 25);//基于qq邮件发送
                client.Credentials = new NetworkCredential(senduser, sendpwd);
                client.EnableSsl = true;
                client.Send(message);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

 

c#基于System.Net.Mail实现发送邮件功能

标签:private   tns   setting   主题   use   void   show   添加引用   eve   

原文地址:http://www.cnblogs.com/a735882640/p/7626980.html

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