復制代碼 代碼如下:
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();
}
}
}
新聞熱點
疑難解答
圖片精選