发送邮件
public static void SendMailUseGmail(string gmailAddress, string gmailPwd, string name, string toAddress, string info, string title)
{
System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
msg.To.Add(toAddress);
msg.From = new MailAddress(toAddress, name, System.Text.Encoding.UTF8);
msg.Subject = title;//邮件标题
msg.SubjectEncoding = System.Text.Encoding.UTF8;//邮件标题编码
msg.Body = info;//邮件内容
msg.BodyEncoding = System.Text.Encoding.UTF8;//邮件内容编码
msg.IsBodyHtml = false;
msg.Priority = MailPriority.High;
SmtpClient client = new SmtpClient();
client.Credentials = new System.Net.NetworkCredential(gmailAddress, gmailPwd);
client.Port = 587;
client.Host = "smtp.gmail.com";
client.EnableSsl = true;
object userState = msg;
try
{
client.Send(msg);
}
catch (System.Net.Mail.SmtpException ex)
{
Console.WriteLine(ex.Message);
}
}
public static void SendMailUseGmail()
{
string userEmail = "123@sina.com";
System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
msg.To.Add(userEmail);
msg.From = new MailAddress(userEmail, "wanhu", System.Text.Encoding.UTF8);
msg.Subject = "这是测试邮件";//邮件标题
msg.SubjectEncoding = System.Text.Encoding.UTF8;//邮件标题编码
msg.Body = DateTime.Now.ToString();//邮件内容
msg.BodyEncoding = System.Text.Encoding.UTF8;//邮件内容编码
msg.IsBodyHtml = false;//是否是HTML邮件
msg.Priority = MailPriority.High;//邮件优先级
SmtpClient client = new SmtpClient();
client.Credentials = new System.Net.NetworkCredential("szwanhu@gmail.com", "9016890168");
//上述写你的GMail邮箱和密码
client.Port = 587;//Gmail使用的端口
client.Host = "smtp.gmail.com";
client.EnableSsl = true;//经过ssl加密
object userState = msg;
try
{
client.Send(msg);
//简单一点儿可以client.Send(msg);
}
catch (System.Net.Mail.SmtpException ex)
{
}
}
{
System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
msg.To.Add(toAddress);
msg.From = new MailAddress(toAddress, name, System.Text.Encoding.UTF8);
msg.Subject = title;//邮件标题
msg.SubjectEncoding = System.Text.Encoding.UTF8;//邮件标题编码
msg.Body = info;//邮件内容
msg.BodyEncoding = System.Text.Encoding.UTF8;//邮件内容编码
msg.IsBodyHtml = false;
msg.Priority = MailPriority.High;
SmtpClient client = new SmtpClient();
client.Credentials = new System.Net.NetworkCredential(gmailAddress, gmailPwd);
client.Port = 587;
client.Host = "smtp.gmail.com";
client.EnableSsl = true;
object userState = msg;
try
{
client.Send(msg);
}
catch (System.Net.Mail.SmtpException ex)
{
Console.WriteLine(ex.Message);
}
}
public static void SendMailUseGmail()
{
string userEmail = "123@sina.com";
System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
msg.To.Add(userEmail);
msg.From = new MailAddress(userEmail, "wanhu", System.Text.Encoding.UTF8);
msg.Subject = "这是测试邮件";//邮件标题
msg.SubjectEncoding = System.Text.Encoding.UTF8;//邮件标题编码
msg.Body = DateTime.Now.ToString();//邮件内容
msg.BodyEncoding = System.Text.Encoding.UTF8;//邮件内容编码
msg.IsBodyHtml = false;//是否是HTML邮件
msg.Priority = MailPriority.High;//邮件优先级
SmtpClient client = new SmtpClient();
client.Credentials = new System.Net.NetworkCredential("szwanhu@gmail.com", "9016890168");
//上述写你的GMail邮箱和密码
client.Port = 587;//Gmail使用的端口
client.Host = "smtp.gmail.com";
client.EnableSsl = true;//经过ssl加密
object userState = msg;
try
{
client.Send(msg);
//简单一点儿可以client.Send(msg);
}
catch (System.Net.Mail.SmtpException ex)
{
}
}