码迷,mamicode.com
首页 > 其他好文 > 详细

调用QQ_Mail发送邮件

时间:2021-06-02 11:41:48      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:color   服务   form   work   支持   efault   案例   size   oid   

调用QQ_Mail发送邮件

代码案例:

  private void button1_Click(object sender, EventArgs e)
        {
            string myMaillAdress = "";
            string myMaillPassword = "";
            string myMaillMessage = "";
            string toMaillAdress = "";

            QQEmail qq_mial = new QQEmail();
            bool send_status = qq_mial.IsSendEmail(myMaillAdress, toMaillAdress, myMaillMessage, myMaillPassword);
        }
        class QQEmail
        {
            public bool IsSendEmail(string FromAddress, string ToAddress, string Message, string Pwd)
            {
                MailAddress Address = new MailAddress(FromAddress);
                MailMessage mail = new MailMessage();
                mail.SubjectEncoding = System.Text.Encoding.UTF8;
                mail.Subject = "这是" + FromAddress + "发送的一段信息:";
                mail.BodyEncoding = System.Text.Encoding.UTF8;
                mail.Body = Message;
                mail.IsBodyHtml = true;

                mail.Priority = System.Net.Mail.MailPriority.Low;
                mail.To.Add(ToAddress);

                mail.From = Address;

                SmtpClient smtp = new SmtpClient("smtp.qq.com", 25);//smtp支持的服务器是smtp.qq.com,服务器端口是25,587也行

                smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
                smtp.EnableSsl = true;
                smtp.UseDefaultCredentials = false;
                smtp.Credentials = new System.Net.NetworkCredential(FromAddress, Pwd);//切记这两个数据一定要填对

                try
                {
                    smtp.Send(mail);
                    return true;
                }
                catch (Exception ex)
                {
                    System.Windows.Forms.MessageBox.Show(ex.Message);
                    return false;
                }
            }
        }

 

调用QQ_Mail发送邮件

标签:color   服务   form   work   支持   efault   案例   size   oid   

原文地址:https://www.cnblogs.com/wml-it/p/14814297.html

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