ASP.NET------メール送信類

8802 ワード

ウェブサイト上でメールサービスでメールを送受信するのは正常ですが、この機能を実現する方法の一つは、このクラスを呼び出すことです.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Mail;
using System.Net;

namespace Core.Common.Service
{
/// <summary>
///
/// </summary>
public static class EMail
{
/// <summary>
///
/// </summary>
/// <param name="to"> </param>
/// <param name="from"> </param>
/// <param name="displayName"> </param>
/// <param name="subject"> </param>
/// <param name="body"> </param>
/// <param name="userName"> smtp , '@' </param>
/// <param name="password"> smtp </param>
/// <param name="smtpHost"> smtp </param>
public static void Send(string to, string from, string displayName, string subject, string body, string userName, string password, string smtpHost)
{
try
{
MailAddress fromaddress
= new MailAddress(from, displayName);
MailAddress toaddress
= new MailAddress(to);
MailMessage message
= new MailMessage(fromaddress, toaddress);
message.Subject
= subject;//
message.BodyEncoding = System.Text.UnicodeEncoding.UTF8;
message.IsBodyHtml
= true;// html
message.Body = body;//
message.Priority = MailPriority.High;
SmtpClient client
= new SmtpClient(smtpHost);
client.DeliveryMethod
= SmtpDeliveryMethod.Network;
//
// [email protected], abc [email protected]
client.Credentials = new NetworkCredential(userName, password);
client.Send(message);
}
catch(Exception ex)
{
DirectoryAndFile.SaveFile(
"abc.txt", ex.GetType().ToString());
}
}
}
}