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

2021-05-08 12:28

阅读:701

标签: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


评论


亲,登录后才可以留言!