Hi Guys
I have a generic code to send email. But there is error
The Name 'Constant' does nt ezists in the current Context.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Net;
using System.Net.Mail;
/// <summary>
/// Summary description for Email_Help
/// </summary>
public class Email_Help
{
private static string EMAIL_SEPARATOR = ",; ";
public static void MailSend(string to, string cc, string bcc, string subject, string body, bool isBodyHtml)
{
MailSend(to, cc, bcc, subject, body, isBodyHtml, MailPriority.High);
}
public static void MailSend(string to, string cc, string bcc, string subject, string body, bool isBodyHtml, MailPriority mailPriority)
{
SmtpClient client = new SmtpClient();
client.Host = Constants.AppSettings.SmtpHost;
client.Port = Constants.AppSettings.SmtpPort;
client.EnableSsl = Constants.AppSettings.SmtpEnableSsl;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
if (Constants.AppSettings.SmtpUseDefaultCredentials.HasValue)
{
client.UseDefaultCredentials = Constants.AppSettings.SmtpUseDefaultCredentials.Value;
client.Credentials = new NetworkCredential(Constants.AppSettings.SmtpUser, Constants.AppSettings.SmtpPass);
}
MailMessage mail = new MailMessage();
mail.From = new MailAddress(Constants.AppSettings.SmtpFromEmail ?? Constants.AppSettings.SmtpUser, Constants.AppSettings.SmtpFromDisplayName);
mail.Subject = subject;
mail.IsBodyHtml = isBodyHtml;
mail.Body = body;
mail.Priority = mailPriority;
#region TO
if (!string.IsNullOrEmpty(to))
{
string[] toArr = to.Split(EMAIL_SEPARATOR.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
if (toArr != null && toArr.Length > 0)
{
foreach (string mailAddr in toArr)
{
if (string.IsNullOrEmpty(mailAddr)) continue;
mail.To.Add(mailAddr);
}
}
}
#endregion
#region CC
if (!string.IsNullOrEmpty(cc))
{
string[] ccArr = cc.Split(EMAIL_SEPARATOR.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
if (ccArr != null && ccArr.Length > 0)
{
foreach (string mailAddr in ccArr)
{
if (string.IsNullOrEmpty(mailAddr)) continue;
mail.CC.Add(mailAddr);
}
}
}
#endregion
#region BCC
if (!string.IsNullOrEmpty(bcc))
{
string[] bccArr = bcc.Split(EMAIL_SEPARATOR.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
if (bccArr != null && bccArr.Length > 0)
{
foreach (string mailAddr in bccArr)
{
if (string.IsNullOrEmpty(mailAddr)) continue;
mail.Bcc.Add(mailAddr);
}
}
}
#endregion
client.Send(mail);
}
}