Asp.net(c#)寄送電子郵件

來源:互聯網
上載者:User
asp.net

using System.web.Mail; 

            MailMessage msg = new MailMessage();
            //發送方地址(如test@163.com)
            msg.From = "zdyguilong@163.com";
            //接收方地址(如test@163.com)
            msg.To = "zdyguilong@163.com";
            //本文內容類型
            msg.BodyFormat = MailFormat.Html;
            //本文內容編碼
            msg.BodyEncoding = System.Text.Encoding.Default;
            //主題
            msg.Subject = "張大宇向您問好";
            //內容
            msg.Body = "<html><head><META content=zh-cn http-equiv=Content-Language><meta http-equiv='Content-Type' content='text/html; charset=gb2312'><style type=text/css>A:link { FONT-SIZE: 9pt; TEXT-DECORATION: none; color: #000000}A:visited {FONT-SIZE: 9pt; TEXT-DECORATION: none; color: #666666}A:hover {COLOR: #ff6600; FONT-SIZE: 9pt; TEXT-DECORATION: underline}BODY {FONT-SIZE: 9pt} --></style></head><body><font color=red>使用者名稱:" + UserName.Text.Trim() + "</font><br><font color=green>密碼:" + strUserPsw.ToString() + "</font><br><b>驗證地址:</b><a href='http://192.168.1.98/AllFiles/Member/CheckFromEmail.aspx?UserName=" + UserName.Text.Trim() + "'target=_blank>http://192.168.1.98/AllFiles/Member/CheckFromEmail.aspx?UserName=" + UserName.Text.Trim() + "</a>。如果您不能點選連結進行跳轉,請把這個地址粘貼到瀏覽器的地址欄直接存取。<br><font color=red>此郵件不必回複,謝謝。</font></body></html>";
            //設定為需要使用者驗證
            msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
            //設定驗證使用者名稱
            msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "zdyguilong");
            //設定驗證密碼
            msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "123456");
            //郵件伺服器地址(如smtp.163.com)
            SmtpMail.SmtpServer = "smtp.163.com";
            //發送
            SmtpMail.Send(msg);
            //Response.Write("<script language='javascript'>alert('註冊成功');window.location='../default.aspx'</script>");



相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.