标签:
using System;
using System.Net;
using System.Net.Mail;
using System.Text;
namespace SendMailDemo
{
class Program
{
static void Main(string[] args)
{
SmtpClient client = new SmtpClient("smtp.goodix.com");
MailAddress from = new MailAddress("aiweiyong@goodix.com", "The Address That Mail Send From", Encoding.UTF8);
//构造一个收件人地址对象
MailAddress to = new MailAddress("aiweiyong@goodix.com", "The Address That Mail Send To", Encoding.UTF8);
//构造一个Email的Message对象
MailMessage message = new MailMessage(from, to);
//添加邮件主题和内容
message.Subject = "测试邮件主题";
message.Body = "测试邮件正文,It‘s Just a Test!";
//设置邮件的信息
client.DeliveryMethod = SmtpDeliveryMethod.Network;
//如果服务器支持安全连接,则将安全连接设为true。
client.EnableSsl = false;
//设置用户名和密码。
client.UseDefaultCredentials = false;
string username = "aiweiyong@goodix.com";
string passwd = "******";
//用户登陆信息
NetworkCredential myCredentials = new NetworkCredential(username, passwd);
client.Credentials = myCredentials;
//发送邮件
client.Send(message);
//提示发送成功
Console.WriteLine("发送成功!");
Console.ReadKey();
}
}
}
标签:
原文地址:http://www.cnblogs.com/Atlas007/p/5227681.html