【转】【Asp.Net】Asp.net发送邮件的两种方法小结
生活随笔
收集整理的這篇文章主要介紹了
【转】【Asp.Net】Asp.net发送邮件的两种方法小结
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
這幾天看了一下Asp.net發送郵件方面的東西,記得之前的IIS6上有SMTP服務器,可以直接利用這個進行郵件發送,現在的開發環境是Windows 7,找了半天沒有找到,到網絡上查了才知道原來windows 7和Vista都將SMTP服務器去掉了,現在將兩種方法總結一下。
?
一,利用大網站的SMTP來發送郵件
這種方法適用于程序運行環境沒有配置SMTP的服務器,想借助于其他smtp來發送郵件的情況,當然需要有此smtp的賬戶才行,例如如果使用Google的SMTP服務器,有三點需要注意:啟用SSL,端口和地址smtp.gmail.com。
?
二,利用本地的smtp來發送郵件
這種方法要求本地有smtp服務器,如果沒有,windows 7和vista上面沒有smtp服務器可以安裝一個軟件,
Free SMTP Server,下載地址:http://www.softstack.com/freesmtp.html或者http://pan.baidu.com/s/1jGG8ZgM,這種方式不用提供用戶名,只需要設置一下IIS即可。
做如下設置:
相關代碼如下:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Net.Mail; namespace IISSendMail { class Program { static void Main(string[] args) { /*第一種,利用Google的smtp來發送郵件*/ SmtpClient client = new SmtpClient("smtp.gmail.com", 25); MailMessage msg = new MailMessage("wengyuli@gmail.com","leonweng@qq.com","這個是標題","這個是內容"); client.UseDefaultCredentials = false; System.Net.NetworkCredential basicAuthenticationInfo = new System.Net.NetworkCredential("username", "password"); client.Credentials = basicAuthenticationInfo; client.EnableSsl = true; client.Send(msg); /*第二種,利用本地的smtp來發送郵件*/ SmtpClient smtp = new SmtpClient("localhost", 25); MailMessage message = new MailMessage("wengyuli@gmail.com", "leonweng@qq.com", "標題:測試一下iis發郵件", "內容:老翁,你好!哈哈"); smtp.Send(message); Console.WriteLine("發送成功!"); Console.Read(); } } }
原文地址:http://www.jb51.net/article/23837.htm
轉載于:https://www.cnblogs.com/mqxs/p/3682088.html
總結
以上是生活随笔為你收集整理的【转】【Asp.Net】Asp.net发送邮件的两种方法小结的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ubuntu 14.04下 horizo
- 下一篇: Cracking The Coding