C#发送邮件-C#教程

时间:2023-12-04 16:53:02

如何利用C#实现邮件发送功能?闲话不多说请看代码:

public static void SendMail(MyEmail email)
{
//发送验证邮箱邮件。
//1.创建邮件
MailMessage mail = new MailMessage();
mail.Subject = email.Title;
mail.SubjectEncoding = System.Text.Encoding.UTF8;
mail.Body = email.Content;
mail.BodyEncoding = System.Text.Encoding.UTF8;
mail.IsBodyHtml = true;

//发件人
mail.From = new MailAddress(“cxx7177@163.com”, email.Subject);

//收件人
mail.To.Add(new MailAddress(email.SendEmail));

//创建一个发送邮件的类
SmtpClient client = new SmtpClient(“smtp.163.com”, 25);
client.Credentials = new NetworkCredential(“帐号”, “密码”);
client.Send(mail);
}

public class MyEmail
{
//string content,string sendEmail,string Uid,string subject
public string Content { get; set; }
public string SendEmail { get; set; }
public string Subject { get; set; }
public string Title { get; set; }
}
}

当然本代码可用于:C#发送邮件,asp.net发送邮件,.net发送邮件,希望可以帮到您

本文链接: http://www.chengxiaoxiao.com/?p=871
转载请注明来源:成笑笑博客 .net技术学习交流 《C#发送邮件-C#教程》