public void SendAutoEmail(SendMailTemplatePro _clsObjSendMailTemplatePro) {
try {
string SmtpServer; //= System.Configuration.ConfigurationManager.AppSettings["SmtpServer"].ToString();
string SmtpPassword; //= System.Configuration.ConfigurationManager.AppSettings["SmtpPassword"].ToString();
string SmtpPort; //= System.Configuration.ConfigurationManager.AppSettings["SmtpPort"].ToString();
string str_from_address; //= System.Configuration.ConfigurationManager.AppSettings["mailaddress"].ToString();
string str_to_address;
string str_cc_address="";
string str_bcc_address="";
Hashtable templateVars = new Hashtable();
templateVars.Add("EmailText", _clsObjSendMailTemplatePro.Body);
Parser parser = new Parser(System.Web.HttpContext.Current.Server.MapPath(_clsObjSendMailTemplatePro.EmailTemplatePath), templateVars);
SmtpServer = _clsObjSendMailTemplatePro.SmtpServer.Trim().ToString();
SmtpPassword=_clsObjSendMailTemplatePro.SmtpPassword.Trim().ToString();
SmtpPort = _clsObjSendMailTemplatePro.SmtpPort.Trim().ToString();
str_from_address = _clsObjSendMailTemplatePro.FromAddress.Trim().ToString();
str_to_address = _clsObjSendMailTemplatePro.ToAddress.ToString();
str_cc_address = _clsObjSendMailTemplatePro.CCAddress.ToString();
str_bcc_address = _clsObjSendMailTemplatePro.BCCAddress.ToString();
MailMessage email_msg = new MailMessage();
email_msg.From = new MailAddress(str_from_address);
email_msg.Sender = new MailAddress(str_from_address);
email_msg.ReplyTo = new MailAddress(str_from_address);
if (str_to_address != "")
{
email_msg.To.Add(str_to_address.Replace(";", ","));
}
if (str_cc_address != "")
{
email_msg.CC.Add(str_cc_address.Replace(";", ","));
}
if (str_bcc_address != "")
{
email_msg.Bcc.Add(str_bcc_address.Replace(";", ","));
}
email_msg.IsBodyHtml = true;
email_msg.BodyEncoding = System.Text.Encoding.UTF8;
string s = parser.Parse();
email_msg.Body = s;
email_msg.Subject = _clsObjSendMailTemplatePro.Subject.ToString();
SmtpClient mail_client = new SmtpClient();
NetworkCredential network_cdr = new NetworkCredential();
network_cdr.UserName = str_from_address;
network_cdr.Password = SmtpPassword;
mail_client.Credentials = network_cdr;
mail_client.Port =Convert.ToInt32(SmtpPort);
mail_client.Host = SmtpServer;
mail_client.EnableSsl = true; //Now Send the message
mail_client.Send(email_msg);
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
finally
{
}
}
|