public static string SendMail(string toMail, string from, string cc, string bcc, string subject, string body, bool isHtml, string pSMTPHost, int pSMTPort, bool isSSL, string pAdminEmail, string pAdminEmailPassword)
{
string mailsended = "no";
// string smtphost = ConfigurationManager.AppSettings["QBSSMTP_Host"];
// int smtpport =Convert.ToInt32(ConfigurationManager.AppSettings["QBSSMTP_Port"]);
// bool isssl =Convert.ToBoolean(ConfigurationManager.AppSettings["QBSEnableSSL"]);
//string adminemail = ConfigurationManager.AppSettings["QBSAdmin_Email"];
//string adminpassword = ConfigurationManager.AppSettings["QBSAdmin_Password"];
SmtpClient smtp = new SmtpClient(pSMTPHost, pSMTPort);
smtp.Credentials = new NetworkCredential(pAdminEmail, pAdminEmailPassword);
smtp.EnableSsl = isSSL;
MailMessage mailmsg = new MailMessage();
//mailmsg.From = new MailAddress(from, Common.GetConfigAppSettingValue("MailDisplayName"));
mailmsg.From = new MailAddress(from, from);
mailmsg.To.Add(toMail);
if (!string.IsNullOrEmpty(cc))
{ mailmsg.CC.Add(cc); }
if (!string.IsNullOrEmpty(bcc))
{ mailmsg.Bcc.Add(bcc); }
if (isSSL == true)
{
ServicePointManager.ServerCertificateValidationCallback = delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; };
}
mailmsg.Body = body;
mailmsg.Subject = subject;
mailmsg.IsBodyHtml = isHtml;
mailmsg.Priority = MailPriority.Normal;
try
{
smtp.Send(mailmsg);
mailmsg.Dispose();
mailsended = "yes";
}
catch (Exception ex)
{
//mailsended = ex.ToString();
}
return mailsended;
}
{
string mailsended = "no";
// string smtphost = ConfigurationManager.AppSettings["QBSSMTP_Host"];
// int smtpport =Convert.ToInt32(ConfigurationManager.AppSettings["QBSSMTP_Port"]);
// bool isssl =Convert.ToBoolean(ConfigurationManager.AppSettings["QBSEnableSSL"]);
//string adminemail = ConfigurationManager.AppSettings["QBSAdmin_Email"];
//string adminpassword = ConfigurationManager.AppSettings["QBSAdmin_Password"];
SmtpClient smtp = new SmtpClient(pSMTPHost, pSMTPort);
smtp.Credentials = new NetworkCredential(pAdminEmail, pAdminEmailPassword);
smtp.EnableSsl = isSSL;
MailMessage mailmsg = new MailMessage();
//mailmsg.From = new MailAddress(from, Common.GetConfigAppSettingValue("MailDisplayName"));
mailmsg.From = new MailAddress(from, from);
mailmsg.To.Add(toMail);
if (!string.IsNullOrEmpty(cc))
{ mailmsg.CC.Add(cc); }
if (!string.IsNullOrEmpty(bcc))
{ mailmsg.Bcc.Add(bcc); }
if (isSSL == true)
{
ServicePointManager.ServerCertificateValidationCallback = delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; };
}
mailmsg.Body = body;
mailmsg.Subject = subject;
mailmsg.IsBodyHtml = isHtml;
mailmsg.Priority = MailPriority.Normal;
try
{
smtp.Send(mailmsg);
mailmsg.Dispose();
mailsended = "yes";
}
catch (Exception ex)
{
//mailsended = ex.ToString();
}
return mailsended;
}
Comments
Post a Comment