Franc Stratton's .NET (TM) Web Application, OOP, and SOA Architecture & Programming Site

A site devoted to ASP.NET (TM), SilverLight (TM) and Browser-Based WPF (TM) Applications, IIS Services, and OOP Architectures

Home     .NET Security     Standards     Data Store     Windows Form Apps     WF/WCF/WPF     jQuery     C# Developer Corner     Java Development     Site Map      
Architecture Overview
N-Tier Architecture
Service Oriented Architecture
SOA Virtualization
Base Classes
BLL
DAL
Base Page
DALFactory
IDAL
Email
Application
Contact Us
Business Entities
Email BLL Class
 
The Email class allows the programmer to format an email with a disclaimer and optional attachments and access their SMPT server to send an email. [Thanks to Kenneth Weems and Jerremy Wilberger for their input.] 
 

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

{

#region Private and Public Variables

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 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.";

#endregion

#region Class Constructors

public EmailBLL()

{

//

// TODO: Add constructor logic here

//

}

#endregion Class Constructors

#region Static Methods

#endregion Static Methods

#region Instance Methods

///---------------------------------------------------------------------------

/// <summary>

/// Method Name: SendEmailwithAttachment

/// Description: call the email object to sends the email with an attachment.

/// </summary>

///---------------------------------------------------------------------------

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();

}

}

}

///---------------------------------------------------------------------------

/// <summary>

/// Method Name: SendEmailNoAttachment

/// Description: call the email object to sends the email without an attachment.

/// </summary>

///---------------------------------------------------------------------------

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();

}

}

#endregion

#region Destructor

// Use C# destructor syntax for finalization code.

~EmailBLL()

{

}

 

#endregion

}

}