Asp.Net送信Email
7481 ワード
/// <summary>
///
/// </summary>
/// <param name="_username"> </param>
/// <param name="_subject"> </param>
/// <param name="_body"> </param>
/// <param name="_url"> </param>
/// <param name="_emailAddress"> </param>
/// <returns></returns>
public void SendMail(string _username, string _subject, string _body, string _url, string _emailAddress)
{
SmtpClient client = new SmtpClient();
// 126
client.Credentials = new System.Net.NetworkCredential(ConfigurationSettings.AppSettings["mailUser"], ConfigurationSettings.AppSettings["mailPwd"]);
client.Port = Convert.ToInt32(ConfigurationSettings.AppSettings["Port"]);//126
client.Host = ConfigurationSettings.AppSettings["mailSmtpServer"];
client.EnableSsl = true;// ssl
try
{
client.Send(InitMail(_subject, _body, _emailAddress));
}
catch (System.Net.Mail.SmtpException ex)
{
}
}
/// <summary>
///
/// </summary>
/// <param name="Subject"> </param>
/// <param name="Body"> </param>
/// <param name="Address"> </param>
/// <returns></returns>
public MailMessage InitMail(string Subject, string Body, string Address)
{
MailMessage mail = new MailMessage();
//
mail.From = new MailAddress("[email protected]");//
//
mail.To.Add(new MailAddress(Address));
//
mail.Subject = Subject;
//
mail.Body = Body;
//
mail.SubjectEncoding = System.Text.Encoding.UTF8;
mail.BodyEncoding = System.Text.Encoding.UTF8;
// Html
mail.IsBodyHtml = true;
//
mail.Priority = MailPriority.High;
//
mail.Bcc.Add(Address);
//
mail.CC.Add(Address);
//
//mail.Attachments.Add(new Attachment("d:\\tes.txt"));
return mail;
}