using System.Net.Mail;
namespace Sample.AppBase{///---------------------------------------------------------------------------
{
///---------------------------------------------------------------------------
/// Namespace: Sample.AppBase
/// Derived Class
/// Filename: EmailBLL.cs
/// Author: Your Team
/// Date: 05/30/2008
/// Updated:
/// <summary>
/// Purpose: Class Contains Properties and Methods used to send emails.
/// </summary>
// Notify the CLR to grant this assembly the IsolatedStorageFilePermission.
// This allows the assembly to work with storage files that are isolated
// by user and assembly.
//[assembly: IsolatedStorageFilePermission(SecurityAction.RequestMinimum, UsageAllowed = IsolatedStorageContainment.AssemblyIsolationByUser)]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1705:LongAcronymsShouldBePascalCased")]public class EmailBLL
public class EmailBLL
#region Private and Public Variablespublic string SendFrom { get; set; } //This will be a valid groupwise account to be set up by Sample
public string SendFrom { get; set; } //This will be a valid groupwise account to be set up by Sample
public string SendFromDisplay { get; set; } //
public string SendTo { get; set; }public string SendCC { get; set; }public string SendBCC { get; set; }public string SendSubject { get; set; }public string SendBody { get; set; }public string SendAttachment { get; set; }public string SMTPServer = "youremailsmpthere"; //Your SMTP Server
public string SendCC { get; set; }public string SendBCC { get; set; }public string SendSubject { get; set; }public string SendBody { get; set; }public string SendAttachment { get; set; }public string SMTPServer = "youremailsmpthere"; //Your SMTP Server
public string SendBCC { get; set; }public string SendSubject { get; set; }public string SendBody { get; set; }public string SendAttachment { get; set; }public string SMTPServer = "youremailsmpthere"; //Your SMTP Server
public string SendSubject { get; set; }public string SendBody { get; set; }public string SendAttachment { get; set; }public string SMTPServer = "youremailsmpthere"; //Your SMTP Server
public string SendBody { get; set; }public string SendAttachment { get; set; }public string SMTPServer = "youremailsmpthere"; //Your SMTP Server
public string SendAttachment { get; set; }public string SMTPServer = "youremailsmpthere"; //Your SMTP Server
public string SMTPServer = "youremailsmpthere"; //Your SMTP Server
public bool IsBodyHTML = false;protected string LegalDisclaimer = "\n\nNOTE: This email may contain PRIVILEGED and CONFIDENTIAL information and is intended only for the use of the specific individual(s) to whom it is addressed. If you are not an intended recipient of this email, you are hereby notified that any unauthorized use, dissemination or copying of this email or the information contained in it or attached to it is strictly prohibited. If you have received this email in error, please delete it and immediately notify the person named below by reply mail. Thank you.";
protected string LegalDisclaimer = "\n\nNOTE: This email may contain PRIVILEGED and CONFIDENTIAL information and is intended only for the use of the specific individual(s) to whom it is addressed. If you are not an intended recipient of this email, you are hereby notified that any unauthorized use, dissemination or copying of this email or the information contained in it or attached to it is strictly prohibited. If you have received this email in error, please delete it and immediately notify the person named below by reply mail. Thank you.";
#endregion
#region Class Constructorspublic EmailBLL(){//
public EmailBLL(){//
//
// TODO: Add constructor logic here
}
#endregion Class Constructors
#region Static Methods
#endregion Static Methods
#region Instance Methods///---------------------------------------------------------------------------
/// Method Name: SendEmailwithAttachment
/// Description: call the email object to sends the email with an attachment.
public void SendEmailwithAttachment(){using (MailMessage msg = new MailMessage()){using (Attachment att = new Attachment(SendAttachment)){SmtpClient mailObject = new SmtpClient(SMTPServer);mailObject.DeliveryMethod = SmtpDeliveryMethod.Network;msg.From = new MailAddress(SendFrom, SendFromDisplay);msg.To.Add(new MailAddress(SendTo));if (SendCC != null){msg.CC.Add(new MailAddress(SendCC));}if (SendBCC != null){msg.Bcc.Add(new MailAddress(SendBCC));}msg.Priority = MailPriority.Normal;msg.Subject = SendSubject;msg.IsBodyHtml = IsBodyHTML;msg.Body = string.Concat(SendBody, LegalDisclaimer);msg.Attachments.Add(att);mailObject.Send(msg);att.Dispose();msg.Dispose();}}}///---------------------------------------------------------------------------
using (MailMessage msg = new MailMessage()){using (Attachment att = new Attachment(SendAttachment)){SmtpClient mailObject = new SmtpClient(SMTPServer);mailObject.DeliveryMethod = SmtpDeliveryMethod.Network;msg.From = new MailAddress(SendFrom, SendFromDisplay);msg.To.Add(new MailAddress(SendTo));if (SendCC != null){msg.CC.Add(new MailAddress(SendCC));}if (SendBCC != null){msg.Bcc.Add(new MailAddress(SendBCC));}msg.Priority = MailPriority.Normal;msg.Subject = SendSubject;msg.IsBodyHtml = IsBodyHTML;msg.Body = string.Concat(SendBody, LegalDisclaimer);msg.Attachments.Add(att);mailObject.Send(msg);att.Dispose();msg.Dispose();}}}///---------------------------------------------------------------------------
using (Attachment att = new Attachment(SendAttachment)){SmtpClient mailObject = new SmtpClient(SMTPServer);mailObject.DeliveryMethod = SmtpDeliveryMethod.Network;msg.From = new MailAddress(SendFrom, SendFromDisplay);msg.To.Add(new MailAddress(SendTo));if (SendCC != null){msg.CC.Add(new MailAddress(SendCC));}if (SendBCC != null){msg.Bcc.Add(new MailAddress(SendBCC));}msg.Priority = MailPriority.Normal;msg.Subject = SendSubject;msg.IsBodyHtml = IsBodyHTML;msg.Body = string.Concat(SendBody, LegalDisclaimer);msg.Attachments.Add(att);mailObject.Send(msg);att.Dispose();msg.Dispose();}}}///---------------------------------------------------------------------------
SmtpClient mailObject = new SmtpClient(SMTPServer);mailObject.DeliveryMethod = SmtpDeliveryMethod.Network;msg.From = new MailAddress(SendFrom, SendFromDisplay);msg.To.Add(new MailAddress(SendTo));if (SendCC != null){msg.CC.Add(new MailAddress(SendCC));}if (SendBCC != null){msg.Bcc.Add(new MailAddress(SendBCC));}msg.Priority = MailPriority.Normal;msg.Subject = SendSubject;msg.IsBodyHtml = IsBodyHTML;msg.Body = string.Concat(SendBody, LegalDisclaimer);msg.Attachments.Add(att);mailObject.Send(msg);att.Dispose();msg.Dispose();}}}///---------------------------------------------------------------------------
mailObject.DeliveryMethod = SmtpDeliveryMethod.Network;msg.From = new MailAddress(SendFrom, SendFromDisplay);msg.To.Add(new MailAddress(SendTo));if (SendCC != null){msg.CC.Add(new MailAddress(SendCC));}if (SendBCC != null){msg.Bcc.Add(new MailAddress(SendBCC));}msg.Priority = MailPriority.Normal;msg.Subject = SendSubject;msg.IsBodyHtml = IsBodyHTML;msg.Body = string.Concat(SendBody, LegalDisclaimer);msg.Attachments.Add(att);mailObject.Send(msg);att.Dispose();msg.Dispose();}}}///---------------------------------------------------------------------------
msg.From = new MailAddress(SendFrom, SendFromDisplay);msg.To.Add(new MailAddress(SendTo));if (SendCC != null){msg.CC.Add(new MailAddress(SendCC));}if (SendBCC != null){msg.Bcc.Add(new MailAddress(SendBCC));}msg.Priority = MailPriority.Normal;msg.Subject = SendSubject;msg.IsBodyHtml = IsBodyHTML;msg.Body = string.Concat(SendBody, LegalDisclaimer);msg.Attachments.Add(att);mailObject.Send(msg);att.Dispose();msg.Dispose();}}}///---------------------------------------------------------------------------
msg.To.Add(new MailAddress(SendTo));if (SendCC != null){msg.CC.Add(new MailAddress(SendCC));}if (SendBCC != null){msg.Bcc.Add(new MailAddress(SendBCC));}msg.Priority = MailPriority.Normal;msg.Subject = SendSubject;msg.IsBodyHtml = IsBodyHTML;msg.Body = string.Concat(SendBody, LegalDisclaimer);msg.Attachments.Add(att);mailObject.Send(msg);att.Dispose();msg.Dispose();}}}///---------------------------------------------------------------------------
if (SendCC != null){msg.CC.Add(new MailAddress(SendCC));}if (SendBCC != null){msg.Bcc.Add(new MailAddress(SendBCC));}msg.Priority = MailPriority.Normal;msg.Subject = SendSubject;msg.IsBodyHtml = IsBodyHTML;msg.Body = string.Concat(SendBody, LegalDisclaimer);msg.Attachments.Add(att);mailObject.Send(msg);att.Dispose();msg.Dispose();}}}///---------------------------------------------------------------------------
msg.CC.Add(new MailAddress(SendCC));}if (SendBCC != null){msg.Bcc.Add(new MailAddress(SendBCC));}msg.Priority = MailPriority.Normal;msg.Subject = SendSubject;msg.IsBodyHtml = IsBodyHTML;msg.Body = string.Concat(SendBody, LegalDisclaimer);msg.Attachments.Add(att);mailObject.Send(msg);att.Dispose();msg.Dispose();}}}///---------------------------------------------------------------------------
if (SendBCC != null){msg.Bcc.Add(new MailAddress(SendBCC));}msg.Priority = MailPriority.Normal;msg.Subject = SendSubject;msg.IsBodyHtml = IsBodyHTML;msg.Body = string.Concat(SendBody, LegalDisclaimer);msg.Attachments.Add(att);mailObject.Send(msg);att.Dispose();msg.Dispose();}}}///---------------------------------------------------------------------------
msg.Bcc.Add(new MailAddress(SendBCC));}msg.Priority = MailPriority.Normal;msg.Subject = SendSubject;msg.IsBodyHtml = IsBodyHTML;msg.Body = string.Concat(SendBody, LegalDisclaimer);msg.Attachments.Add(att);mailObject.Send(msg);att.Dispose();msg.Dispose();}}}///---------------------------------------------------------------------------
msg.Priority = MailPriority.Normal;msg.Subject = SendSubject;msg.IsBodyHtml = IsBodyHTML;msg.Body = string.Concat(SendBody, LegalDisclaimer);msg.Attachments.Add(att);mailObject.Send(msg);att.Dispose();msg.Dispose();}}}///---------------------------------------------------------------------------
msg.Subject = SendSubject;
msg.IsBodyHtml = IsBodyHTML;
msg.Body = string.Concat(SendBody, LegalDisclaimer);msg.Attachments.Add(att);mailObject.Send(msg);att.Dispose();msg.Dispose();}}}///---------------------------------------------------------------------------
msg.Attachments.Add(att);
mailObject.Send(msg);
att.Dispose();
msg.Dispose();
/// Method Name: SendEmailNoAttachment
/// Description: call the email object to sends the email without an attachment.
public void SendEmailNoAttachment(){using (MailMessage msg = new MailMessage()){SmtpClient mailObject = new SmtpClient(SMTPServer);mailObject.DeliveryMethod = SmtpDeliveryMethod.Network;msg.From = new MailAddress(SendFrom, SendFromDisplay);msg.To.Add(new MailAddress(SendTo));if (SendCC != null){msg.CC.Add(new MailAddress(SendCC));}if (SendBCC != null){msg.Bcc.Add(new MailAddress(SendBCC));}msg.Priority = MailPriority.Normal;msg.Subject = SendSubject;msg.IsBodyHtml = IsBodyHTML;msg.Body = string.Concat(SendBody, LegalDisclaimer);mailObject.Send(msg);msg.Dispose();}}
using (MailMessage msg = new MailMessage()){SmtpClient mailObject = new SmtpClient(SMTPServer);mailObject.DeliveryMethod = SmtpDeliveryMethod.Network;msg.From = new MailAddress(SendFrom, SendFromDisplay);msg.To.Add(new MailAddress(SendTo));if (SendCC != null){msg.CC.Add(new MailAddress(SendCC));}if (SendBCC != null){msg.Bcc.Add(new MailAddress(SendBCC));}msg.Priority = MailPriority.Normal;msg.Subject = SendSubject;msg.IsBodyHtml = IsBodyHTML;msg.Body = string.Concat(SendBody, LegalDisclaimer);mailObject.Send(msg);msg.Dispose();}}
SmtpClient mailObject = new SmtpClient(SMTPServer);mailObject.DeliveryMethod = SmtpDeliveryMethod.Network;msg.From = new MailAddress(SendFrom, SendFromDisplay);msg.To.Add(new MailAddress(SendTo));if (SendCC != null){msg.CC.Add(new MailAddress(SendCC));}if (SendBCC != null){msg.Bcc.Add(new MailAddress(SendBCC));}msg.Priority = MailPriority.Normal;msg.Subject = SendSubject;msg.IsBodyHtml = IsBodyHTML;msg.Body = string.Concat(SendBody, LegalDisclaimer);mailObject.Send(msg);msg.Dispose();}}
mailObject.DeliveryMethod = SmtpDeliveryMethod.Network;msg.From = new MailAddress(SendFrom, SendFromDisplay);msg.To.Add(new MailAddress(SendTo));if (SendCC != null){msg.CC.Add(new MailAddress(SendCC));}if (SendBCC != null){msg.Bcc.Add(new MailAddress(SendBCC));}msg.Priority = MailPriority.Normal;msg.Subject = SendSubject;msg.IsBodyHtml = IsBodyHTML;msg.Body = string.Concat(SendBody, LegalDisclaimer);mailObject.Send(msg);msg.Dispose();}}
msg.From = new MailAddress(SendFrom, SendFromDisplay);msg.To.Add(new MailAddress(SendTo));if (SendCC != null){msg.CC.Add(new MailAddress(SendCC));}if (SendBCC != null){msg.Bcc.Add(new MailAddress(SendBCC));}msg.Priority = MailPriority.Normal;msg.Subject = SendSubject;msg.IsBodyHtml = IsBodyHTML;msg.Body = string.Concat(SendBody, LegalDisclaimer);mailObject.Send(msg);msg.Dispose();}}
msg.To.Add(new MailAddress(SendTo));if (SendCC != null){msg.CC.Add(new MailAddress(SendCC));}if (SendBCC != null){msg.Bcc.Add(new MailAddress(SendBCC));}msg.Priority = MailPriority.Normal;msg.Subject = SendSubject;msg.IsBodyHtml = IsBodyHTML;msg.Body = string.Concat(SendBody, LegalDisclaimer);mailObject.Send(msg);msg.Dispose();}}
if (SendCC != null){msg.CC.Add(new MailAddress(SendCC));}if (SendBCC != null){msg.Bcc.Add(new MailAddress(SendBCC));}msg.Priority = MailPriority.Normal;msg.Subject = SendSubject;msg.IsBodyHtml = IsBodyHTML;msg.Body = string.Concat(SendBody, LegalDisclaimer);mailObject.Send(msg);msg.Dispose();}}
msg.CC.Add(new MailAddress(SendCC));}if (SendBCC != null){msg.Bcc.Add(new MailAddress(SendBCC));}msg.Priority = MailPriority.Normal;msg.Subject = SendSubject;msg.IsBodyHtml = IsBodyHTML;msg.Body = string.Concat(SendBody, LegalDisclaimer);mailObject.Send(msg);msg.Dispose();}}
if (SendBCC != null){msg.Bcc.Add(new MailAddress(SendBCC));}msg.Priority = MailPriority.Normal;msg.Subject = SendSubject;msg.IsBodyHtml = IsBodyHTML;msg.Body = string.Concat(SendBody, LegalDisclaimer);mailObject.Send(msg);msg.Dispose();}}
msg.Bcc.Add(new MailAddress(SendBCC));}msg.Priority = MailPriority.Normal;msg.Subject = SendSubject;msg.IsBodyHtml = IsBodyHTML;msg.Body = string.Concat(SendBody, LegalDisclaimer);mailObject.Send(msg);msg.Dispose();}}
msg.Priority = MailPriority.Normal;msg.Subject = SendSubject;msg.IsBodyHtml = IsBodyHTML;msg.Body = string.Concat(SendBody, LegalDisclaimer);mailObject.Send(msg);msg.Dispose();}}
msg.Body = string.Concat(SendBody, LegalDisclaimer);mailObject.Send(msg);msg.Dispose();}}
#region Destructor// Use C# destructor syntax for finalization code.
// Use C# destructor syntax for finalization code.
~EmailBLL()