时间:2021-07-01 10:21:17 帮助过:21人阅读
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();
}
}
}
作者:cnblogs LeonWeng