No 49 · 微软自带的发送邮件的方法

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Net.Mail;
using System.Data.SqlClient;
namespace guid
{
    public partial class e_mailSend : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            
        }
        
        protected void Button1_Click(object sender, EventArgs e)
        {
            MailAddress mail_send = new MailAddress("[email protected]");
            MailAddress mail_res = new MailAddress(this.txtEmail.Text);
            MailMessage mailmsg = new System.Net.Mail.MailMessage(mail_send, mail_res);
            mailmsg.Priority = MailPriority.High;//优先级
              mailmsg.Subject = "发送实验";//标题
              mailmsg.Body = "收到了吗?";//内容
              SmtpClient Client = new SmtpClient("smtp.163.com");
            Client.Credentials = new System.Net.NetworkCredential("[email protected]", "123");
            //处理待发邮件的方法
            Client.DeliveryMethod = SmtpDeliveryMethod.Network;
            try
            {
                Client.Send(mailmsg);
            }
            catch (SmtpFailedRecipientsException ex)
            {
                for (int i = 0; i < ex.InnerExceptions.Length; i++)
                {
                    SmtpStatusCode status = ex.InnerExceptions[i].StatusCode;
                    if (status == SmtpStatusCode.MailboxBusy || status == SmtpStatusCode.MailboxUnavailable)
                    {
                        this.labMsg.Text = "发送失败,5秒钟之后重试";
                        System.Threading.Thread.Sleep(5000);
                        Client.Send(mailmsg);
                    }
                    else
                    {
                        this.labMsg.Text = "无法提供的信息" + ex.FailedRecipient[i].ToString().Trim();
                    }
                }
            } 
        } 
    }
}

 

你可能感兴趣的:(No 49 · 微软自带的发送邮件的方法)