標籤:技術 ges password bsp 並發 asp 添加 images message
1.擷取QQ郵箱的授權碼
開啟QQ郵箱 - 設定 - 賬戶 - 開啟POP3/SMTP服務 -> 根據操作擷取授權碼
2.設定並發送郵件——方法1
(兩種配置方式)
-1:配置Web.config,在<configuration>標籤中添加以下代碼
(aaaaaaaaaa:表示你發信人的郵箱號.
bbbbbbbbbb:表示你前面擷取的授權碼.
連接埠號碼port:我測試25能發,而465不能發(不知道為什麼).)
<system.net> <mailSettings> <smtp deliveryMethod="Network" from="nekorz <[email protected]>"> <network host="smtp.qq.com" userName="[email protected]" password="bbbbbbbbbb" port="25" /> </smtp> </mailSettings></system.net>
-2:添加發送郵件代碼
(暱稱:可有可無)
MailMessage myMessage = new MailMessage(); myMessage.Subject = "Test Message"; myMessage.Body = "這是一封測試郵件."; myMessage.To.Add(new MailAddress("[email protected]", "暱稱")); SmtpClient mySmtpClient = new SmtpClient(); mySmtpClient.EnableSsl = true; try { mySmtpClient.Send(myMessage); } catch (SmtpException ex) { }
3.設定並發送郵件——方法2
(僅是把在Web.config中的配置,轉移到了代碼中)
MailMessage myMessage = new MailMessage(); myMessage.Subject = "Test Message"; myMessage.Body = "這是一封測試郵件"; myMessage.From = new MailAddress("[email protected]", "暱稱"); myMessage.To.Add(new MailAddress("[email protected]", "暱稱")); SmtpClient mySmtpClient = new SmtpClient(); mySmtpClient.Host = "smtp.qq.com"; mySmtpClient.Port = 25; mySmtpClient.Credentials = new System.Net.NetworkCredential("[email protected]", "bbbbbbbbbb"); mySmtpClient.EnableSsl = true; try { mySmtpClient.Send(myMessage); } catch (SmtpException ex) { }
asp.net——QQ郵箱發送郵件