C#发送邮件
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了C#发送邮件相关的知识,希望对你有一定的参考价值。
直接附录主要的代码吧
static void Main(string[] args)
{
SmtpClient client = new SmtpClient("smtp.126.com");
MailAddress from = new MailAddress("*****@126.com", "***", Encoding.UTF8);//发信箱
MailAddress to = new MailAddress("*****@qq.com", "****", Encoding.UTF8);//收信地址
MailMessage message = new MailMessage(from, to);
Attachment atta = new Attachment(@"C:\Users\HBD\Desktop\蔡英文520就职演说全文.txt");//文件路径
message.Attachments.Add(atta);
message.Subject = "测试主题";
message.SubjectEncoding = Encoding.UTF8;
message.Body = "邮件内容";
message.BodyEncoding = Encoding.UTF8;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
NetworkCredential myNP = new NetworkCredential("*******@126.com", "*****");//账户和密码
client.Credentials = myNP;
client.Send(message);
}
以上是关于C#发送邮件的主要内容,如果未能解决你的问题,请参考以下文章