///<summary>
///发送邮件链接式
///</summary>
///<param name="userName">接邮件者称呼</param>
///<param name="userEmail">接邮件者地址</param>
///<param name="strSendUrl">邮件的链接地址</param>
public static void send(string userName, string userEmail, string strSendUrl)
{
MailAddress from = new MailAddress("*****@yahoo.com.cn", "发送者");
MailAddress to = new MailAddress(userEmail, userName);
MailMessage message = new MailMessage(from, to);
message.IsBodyHtml = true;
message.Subject = "注册测试";
//发送链接
message.Body = "<a href='" + strSendUrl + "'>激活</a>";
//发送html页
// message.Body = strSendUrl;
// message.Body=HttpContent("http://www.flycatch.com");
//定义邮件正文,主题的编码方式
message.BodyEncoding = System.Text.Encoding.GetEncoding("UTF-8");
message.SubjectEncoding = System.Text.Encoding.GetEncoding("UTF-8");
//指定邮件优先级
message.Priority = System.Net.Mail.MailPriority.High;
SmtpClient smpt = new SmtpClient();
smpt.EnableSsl = true;
try
{
//发送
smpt.Send(message);
}
catch (System.Net.Mail.SmtpException ex)
{
}
}
///<summary>
///发邮件非链接式
///</summary>
///<param name="pUserID">邮件的主体内容</param>
///<param name="pUserPassWord">邮件主题</param>
public static void SendEmailFrom(string pUserID, string pUserPassWord)
{
MailAddress from = new MailAddress("****@gmail.com", "发送者");
MailAddress to = new MailAddress("****@gmail.com", "收件者");
MailMessage message = new MailMessage(from, to);
message.IsBodyHtml = true;
message.Subject = "邮件主题";
//发送链接
message.Body ="邮件内容";
//发送html页
// message.Body = strSendUrl;
// message.Body=HttpContent("http://www.flycatch.com");
//定义邮件正文,主题的编码方式
message.BodyEncoding = System.Text.Encoding.GetEncoding("UTF-8");
message.SubjectEncoding = System.Text.Encoding.GetEncoding("UTF-8");
//指定邮件优先级
message.Priority = System.Net.Mail.MailPriority.High;
SmtpClient smpt = new SmtpClient();
smpt.Host = "smtp.gmail.com";
smpt.Port = 587;
smpt.UseDefaultCredentials = false;
smpt.Credentials = new System.Net.NetworkCredential(from.Address, "Send邮箱密码");
//ssl安全模式开启
smpt.EnableSsl = true;
//邮件通过网络发送到服务器
smpt.DeliveryMethod = SmtpDeliveryMethod.Network;
try
{
smpt.Send(message);
}
catch
{
throw;
}
finally
{
//及时释放占用的资源
message.Dispose();
}
}
目前测试的网易邮箱服务器不支持 ,发送端口25,接受端口为110.