using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Net.Mail;
using System.Configuration;
public sealed class MailHelper
{
public static void Send(string toAccount, string subject, string body)
{
string fromAccount =
ConfigHelper.GetValue("mailAccount");
string fromPassword =
ConfigHelper.GetValue("mailPassword");
string mailHost =
ConfigHelper.GetValue("mailHost");
int mailPort = Convert.ToInt32(
ConfigHelper.GetValue("fromPort"));
var fromAddress = new MailAddress(fromAccount, fromAccount);
var toAddress = new MailAddress(toAccount, toAccount);
var smtp = new SmtpClient
{
Host = mailHost,
Port = mailPort,
EnableSsl = true,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
Credentials = new NetworkCredential(fromAddress.Address, fromPassword)
};
using (var message = new MailMessage(fromAddress, toAddress)
{
Subject = subject,
Body = body
})
{
smtp.Send(message);
}
}
}