asp.net發送郵件

來源:互聯網
上載者:User

標籤:style   blog   color   io   os   ar   for   sp   div   

首先添加命名空間using System.Net.Mail;  /// <summary>        /// 發送郵件        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        protected void ForMail(string name, string mail)        {            try            {                //string email = txtemail.Text.Trim();                MailAddress MessageFrom = new MailAddress("【寄件匣地址】"); //寄件者郵箱地址                string MessageTo = mail; //收件者郵箱地址                string MessageSubject = bs.HtmlEncode(web_zt.Value.Trim()); //郵件主題                  string MessageBody = "" + content1.Value.Trim() + ""; //郵件內容 (一般是一個網址連結,產生隨機數加驗證id參數,點擊去網站驗證。)";                if (Send(MessageFrom, MessageTo, MessageSubject, MessageBody))                {                    //Response.Write("發送郵件成功");                }                else                {                    //Response.Write("發送郵件失敗");                }            }            catch            {                //ClientScript.RegisterStartupScript(ClientScript.GetType(), "myscript", "<script>alert(‘客戶資訊刪除失敗‘)</script>");            }        }        /// <summary>        /// 寄送電子郵件        /// </summary>        /// <param name="MessageFrom">寄件者郵箱地址</param>        /// <param name="MessageTo">收件者郵箱地址</param>        /// <param name="MessageSubject">郵件主題</param>        /// <param name="MessageBody">郵件內容</param>        /// <returns></returns>        public bool Send(MailAddress MessageFrom, string MessageTo, string MessageSubject, string MessageBody)        {            MailMessage message = new MailMessage();            message.From = MessageFrom;            message.To.Add(MessageTo); //收件者郵箱地址可以是多個以實現群發            message.Subject = MessageSubject;            message.Body = MessageBody;            message.IsBodyHtml = true; //是否為html格式            message.Priority = MailPriority.Normal; //發送郵件的優先等級            SmtpClient sc = new SmtpClient();            sc.Host = "smtp.qq.com"; //指定發送郵件的伺服器位址或IP            sc.Port = 25; //指定發送郵件連接埠            sc.Credentials = new System.Net.NetworkCredential("【寄件匣地址】", "【寄件匣密碼】"); //指定登入伺服器的使用者名稱和密碼(寄件者的郵箱登陸密碼)            try            {                sc.Send(message); //發送郵件            }            catch            {                return false;            }            return true;        }

 

asp.net發送郵件

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.