C#利用stmp服务开发邮件发送功能源码
在日常开发中经常需要将一些数据发送到邮箱起到通知作用,我们这里使用stmp连接邮箱来实现邮件发送能,源码如下:
//添加引用
using System.Net.Mail;
//邮件发送方法传如接收地址,邮件主题、内容
public void Email(string jiename, string zhuti, string neirong)
{
string faname = "xxx@qq.com";
string famima = "邮箱密码";
string server = "smtp.qq.com";
System.Net.Mail.SmtpClient client = new SmtpClient();
client.Host = server;
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential(faname, famima);
client.DeliveryMethod = SmtpDeliveryMethod.Network;
System.Net.Mail.MailMessage message = new MailMessage(faname, jiename);
message.Subject = zhuti;
message.Body = neirong;
message.BodyEncoding = System.Text.Encoding.UTF8;
message.IsBodyHtml = true;
client.Send(message);
}