public static Send ( string subject, string body, string recipients ) : bool | ||
subject | string | Subject text for the message |
body | string | Body text for the message |
recipients | string | A comma-delimited list of recipients that will receive the message |
return | bool |
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;
}
}
/// <summary> /// Send EMail from WebStore User /// </summary> /// <param name="toEMail">recipient email address</param> /// <param name="toName">tomail</param> /// <param name="subject">subject</param> /// <param name="message">message</param> /// <returns>true if sent</returns> public Boolean SendEMail(String toEMail, String toName, String subject, String message) { if (message == null || message.Length == 0) { log.Warning("No Message"); return(false); } StringBuilder msgText = new StringBuilder(); if (GetEMailHeader() != null) { msgText.Append(GetEMailHeader()); } msgText.Append(message); if (GetEMailFooter() != null) { msgText.Append(GetEMailFooter()); } // EMail email = CreateEMail(toEMail, toName, subject, msgText.ToString()); if (email == null) { return(false); } try { String msg = email.Send(); if (EMail.SENT_OK.Equals(email.Send())) { log.Info("Sent EMail " + subject + " to " + toEMail); return(true); } else { log.Warning("Could NOT Send Email: " + subject + " to " + toEMail + ": " + msg + " (" + GetName() + ")"); return(false); } } catch (Exception ex) { log.Severe(GetName() + " - " + ex.Message); return(false); } } // sendEMail