public static bool Send(string subject, string body, string recipients)
{
if (recipients.Length < 1)
{
return false;
}
WebSettings ws = new WebSettings();
// Get the configured EMail infromation from the web config
string EmailAccount = ws.Lookup("EmailAccount");
string EmailPassword = ws.Lookup("EmailPassword");
string EmailSender = ws.Lookup("EmailSender");
string EmailReplyTo = ws.Lookup("EmailReplyTo");
string EmailSenderName = ws.Lookup("EmailSenderName");
string EmailServer = ws.Lookup("EmailServer");
int EmailPort = WebConvert.ToInt32(ws.Lookup("EmailPort", "25"), 25);
// make the credentials for connecting to the server
NetworkCredential smtpuser = new NetworkCredential(EmailAccount, EmailPassword);
// create the mail message
MailMessage mail = new MailMessage();
mail.From = new MailAddress(EmailSender, EmailSenderName);
mail.To.Add(recipients);
mail.ReplyToList.Add(new MailAddress(EmailReplyTo));
mail.Sender = new MailAddress(EmailSender);
mail.Subject = subject;
mail.Body = body;
mail.IsBodyHtml = false;
// connect to the smtp client and send the message
SmtpClient client = new SmtpClient(EmailServer);
client.UseDefaultCredentials = false;
client.Credentials = smtpuser;
client.Port = EmailPort;
client.Send(mail);
return true;
}
}