using System;
namespace nsSendBasicEmailV3HardCoded
{
public class clsSendBasicEmailV3HardCoded
{
//**********************************************
// Self Contained, Simple Email Routine
//**********************************************
// with defaults designed for sending website error
// diagnostic emails
public void stcSendBasicEmailV3HardCoded(
String MTo,
String MFrom,
String MReplyTo,
String MSubject,
ref System.Text.StringBuilder MBody)
{
// use the newer StringBuilder class to formulate the body text of the email
// (instead of a simple string object that would be destroyed and recreated
// with each change in value)
// Declare and instance the service program that will send the message and
// interact with the SMTP server as a client
System.Net.Mail.SmtpClient SMTPClientService = new System.Net.Mail.SmtpClient();
// tell it the IP address of the SMTP server and
// the sender's (or an account holder's) email address and password
SMTPClientService.Host = "mail.YOURMAILSERVERURL.com";
// tell the SMTP service what port to use
SMTPClientService.Port = Convert.ToInt32("1710");
// set the credentials, which is basically an email account and it's password,
// based on application keys (specified in web.config)
SMTPClientService.Credentials = new System.Net.NetworkCredential(
"Webmaster@YOURMAILSERVER.com",
"YourPASSword1234");
// the service program that will send the message and
// interact with the SMTP server as a client has already been declared and instanced and
// provided with a host name and credentials
// Declare and instance the email object
System.Net.Mail.MailMessage EmailMsgObj = new System.Net.Mail.MailMessage();
EmailMsgObj.IsBodyHtml = true;
// the .To and .ReplyTo properties became collections in .NET 2.0
// the .ReplyToList property was added in .NET 4.0 and is now preferred over .ReplyTo
// two initializing options, one is a simple string, the other is a mail address object
if (MTo == "*default" || MTo == String.Empty)
EmailMsgObj.To.Add("WebsiteSupportMgr@YOURMAILSERVER.com");
else
EmailMsgObj.To.Add(MTo);
if (MFrom == "*default" || MFrom == String.Empty)
MFrom = "Webmaster@YOURMAILSERVER.com";
EmailMsgObj.From = new System.Net.Mail.MailAddress(MFrom);
if (MReplyTo == "*default" || MReplyTo == String.Empty)
EmailMsgObj.ReplyToList.Add("Webmaster@YOURMAILSERVER.com");
else
EmailMsgObj.ReplyToList.Add(MReplyTo);
EmailMsgObj.Subject = MSubject;
EmailMsgObj.Body = MBody.ToString();
// SMTPClientService.Send is very stable and probably does not error out even if email not sent
// thus no need to monitor for error condition
// (especiallly since this routine is used primarily to send diagnostic error emails to the webmaster)
SMTPClientService.Send(EmailMsgObj);
}
}
}
|