1.发件
System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient();
client.Host = "smtp.126.com";//使用163的SMTP服务器发送邮件
client.UseDefaultCredentials = true;
client.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
//*******为自己密码或授权码
client.Credentials = new System.Net.NetworkCredential("shihao316558512", "*******");
System.Net.Mail.MailMessage Message = new System.Net.Mail.MailMessage();
Message.From = new System.Net.Mail.MailAddress("shihao316558512@126.com");
Message.To.Add("316558512@qq.com");//将邮件发送给QQ邮箱
Message.Subject = "测试标体";
Message.Body = "测试邮件体";
Message.SubjectEncoding = System.Text.Encoding.UTF8;
Message.BodyEncoding = System.Text.Encoding.UTF8;
Message.Priority = System.Net.Mail.MailPriority.High;
Message.IsBodyHtml = true;
client.Send(Message);
2.收件
using (Pop3Client client = new Pop3Client())
{
client.Connect("pop.126.com", 110, false);
//账号,*******为密码或者授权码,认证方式
client.Authenticate("shihao316558512", "**********", AuthenticationMethod.Auto); //登录认证
int count = client.GetMessageCount(); //获取邮箱总数
int size = client.GetMessageSize(1); //获取编号为1的邮件的大小
OpenPop.Mime.Message msg = client.GetMessage(1); //获取编号为1的邮件的内容
string title = msg.Headers.Subject;
//client.DeleteMessage(1); //标记编号为1的邮件为"删除"
//...
}