Click here to Skip to main content
11,576,993 members (61,648 online)
Click here to Skip to main content
Articles » Web Development » ASP.NET » General » Downloads
Add your own
alternative version

Invoke .Net Assembly using SSIS:Email Framework

, 21 Oct 2008 CPOL 31.9K 182 27
This article demonstrate use of SSIS package that helps in invoking .Net Assembly having email component in it.
EmailFramework.zip
EmailFramework
EmailFramework
EmailFramework
bin
Debug
EmailFramework.dll
EmailTemplateParser.dll
EmailFrameworkKey.snk
Properties
EmailFramework.dll
EmailFrameworkKey.snk
EmailTemplate
EmailTemplateParser.dll
EmailTemplateParser.snk
gacutil.exe
NotifyCreditCardDue_Activex_SSIS_PKG
NotifyCreditCardDue_Activex_SSIS_PKG.dtsx
using System; 
using System.Collections.Generic;
using System.Collections;
using System.Text; 
using System.Configuration; 
using System.Net; 
using System.Net.Mail; 

using EmailTemplateParser; 
using System.Reflection; 
using System.Web; 
using System.Xml; 



namespace EmailFramework 
{ 
    public class EmailServices 
    { 
        
        #region "Private Members" 
        private const string C_SMTP_HOST_NAME = "SMTPServerName"; 
        private const string C_IS_PRODUCTION = "IsProduction"; 
        private const string C_TO_TEST_ID = "ToTestID"; 
        private const string C_PORT_NUMBER = "PortNumber"; 
        private const int C_DEFAULT_PORT = 25; 
        private const string C_ALLOW_SEND_EMAIL = "IsSendMail"; 
        private const string C_IS_MONITORING_MODULE = "IsMonitoringService"; 
        private static IDictionary<string, string> emailSettings = new Dictionary<string, string>(); 
        
        #endregion 
        
        static EmailServices() 
        { 
            XmlDocument xmlDocument = new XmlDocument(); 
            xmlDocument.Load("D:/EmailFramework/EmailFramework/EmailFramework/app.config"); 
            XmlNodeList nodeList = xmlDocument.SelectNodes("configuration/appSettings/add"); 
            int index = 0; 
            
            foreach (XmlNode node in nodeList) { 
                string key = node.Attributes.GetNamedItem("key").Value; 
                string value = node.Attributes.GetNamedItem("value").Value; 
                emailSettings.Add(key, value); 
                index += 1; 
            } 
        } 
        
        public static void GenerateTraceLog(string content) 
        { 
            System.IO.File.AppendAllText(emailSettings["EmailTraceLogPath"], content); 
        } 
        
        #region "Email Component" 
        
        public static void SendRegisterNotification(MailContent mailContent, Hashtable templateVars, string templateFileName) 
        { 
            string hostName = null; 
            System.Net.Mail.SmtpClient smtpClient = null; 
            int port = 0; 
            MailMessage mailMessage = new MailMessage(); 
            
            
            try { 
                hostName = emailSettings["SMTPServerName"]; 
                if (hostName == null | hostName == string.Empty) { 
                    throw new Exception("Invalid Configuration. The configuration could not be found. Please contact support professionals."); 
                } 
                port = Convert.ToInt16(emailSettings["PortNumber"]); 
                
                if (port == 0) { 
                    port = C_DEFAULT_PORT; 
                } 
                
                GenerateTraceLog("***EMAIL SENDING REPORT STARTED*****"); 
                
                // Creating the instance of SMTP Client 
                smtpClient = new SmtpClient(hostName, port); 
                smtpClient.EnableSsl = false; 
                
                
                
                
                GenerateTraceLog("Mail From :" + mailContent.MailFrom); 
                if ((Convert.ToInt16(emailSettings["IsProduction"]) == 1)) { 
                    //TO List 
                    if ((mailContent.ToList == null)) { 
                        GenerateTraceLog("Mail To :" + mailContent.MailTo); 
                        mailMessage = new MailMessage(mailContent.MailFrom, mailContent.MailTo); 
                    } 
                    else { 
                        foreach (string recipient in mailContent.ToList) { 
                            
                            GenerateTraceLog("To List :" + recipient); 
                            mailMessage.To.Add(new MailAddress(recipient)); 
                            
                        } 
                        mailMessage.From = new MailAddress(mailContent.MailFrom); 
                    } 
                    //CC List 
                    if ((mailContent.CCList == null)) { 
                        GenerateTraceLog("CC :" + mailContent.MailCC); 
                        if ((string.IsNullOrEmpty(mailContent.MailCC) == false)) { 
                            mailMessage.CC.Add(mailContent.MailCC); 
                        } 
                    } 
                    else { 
                        foreach (string recipient in mailContent.CCList) { 
                            GenerateTraceLog("CC List :" + recipient); 
                            mailMessage.CC.Add(new MailAddress(recipient)); 
                        } 
                    } 
                    //BCC List 
                    if ((mailContent.BCCList == null)) { 
                        GenerateTraceLog("BCC :" + mailContent.MailBCC); 
                        if ((string.IsNullOrEmpty(mailContent.MailBCC) == false)) { 
                            mailMessage.Bcc.Add(mailContent.MailBCC); 
                        } 
                    } 
                    else { 
                        foreach (string recipient in mailContent.BCCList) { 
                            GenerateTraceLog("BCC List :" + recipient); 
                            mailMessage.Bcc.Add(new MailAddress(recipient)); 
                        } 
                    } 
                } 
                
                else { 
                    mailMessage = new MailMessage(mailContent.MailFrom, emailSettings["ToTestID"]); 
                } 
                
                //Subject 
                GenerateTraceLog("Subject :" + mailContent.Subject); 
                mailMessage.Subject = mailContent.Subject; 
                
                //Attachment 
                //This internal attachment through system 
                
                if ((string.IsNullOrEmpty(mailContent.AttachmentPath) == false)) { 
                    GenerateTraceLog("AttachmentPath :" + mailContent.AttachmentPath); 
                    Attachment mailAttachment = new Attachment(mailContent.AttachmentPath); 
                    mailMessage.Attachments.Add(mailAttachment); 
                } 
                
                Attachment mailAttachmentEntity = null; 
                
                if ((mailContent.AttachmentList != null)) { 
                    foreach (string attachmentPath in mailContent.AttachmentList) { 
                        GenerateTraceLog("AttachmentPath :" + attachmentPath); 
                        mailAttachmentEntity = new Attachment(attachmentPath); 
                        mailMessage.Attachments.Add(mailAttachmentEntity); 
                    } 
                } 
                
                
                //This is uploaded using external interface. 
                if ((string.IsNullOrEmpty(mailContent.AttachmentFileName) == false)) { 
                    GenerateTraceLog("External Attachment :" + mailContent.AttachmentFileName); 
                    Attachment mailAttachment = new Attachment(mailContent.AttachmentFileContent, mailContent.AttachmentFileName); 
                    mailMessage.Attachments.Add(mailAttachment); 
                } 
                
                mailMessage.IsBodyHtml = mailContent.IsBodyHTML; 
                mailMessage.Priority = (MailPriority)mailContent.MessagePriority; 
                
                //Parse Email Template 
                if ((string.IsNullOrEmpty(mailContent.MessageText) == true)) {                     
                    EmailTemplateParser.EmailTemplateParser.Parser parser = null; 
                    parser = new EmailTemplateParser.EmailTemplateParser.Parser(templateFileName, templateVars); 
                    mailMessage.Body = parser.Parse();
                    GenerateTraceLog("Body:" + parser.Parse()); 
                } 
                else { 
                    GenerateTraceLog("Body "); 
                    GenerateTraceLog("Body Content :" + mailContent.MessageText); 
                    mailMessage.Body = mailContent.MessageText; 
                } 
                
                if ((Convert.ToString(emailSettings["IsSendMail"]) == "NO")) { 
                    GenerateTraceLog("*****EMAIL SENDING REPORT ENDED******"); 
                    mailMessage.Dispose(); 
                    return; 
                } 
                else { 
                    smtpClient.Send(mailMessage); 
                    mailMessage.Dispose(); 
                } 
                
                GenerateTraceLog("*****EMAIL SENDING REPORT ENDED******"); 
            } 
            
            catch (Exception ex) { 
                GenerateTraceLog(ex.Message + "***ERROR SENDING EMAIL THROUGH APPLICATION *****"); 
            } 
        } 
        #endregion 
        
    } 
} 

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

santosh poojari
Technical Lead
India India
Whatsup-->Exploring--> MVC/HTML5/Javascript & Virtualization.......!
www.santoshpoojari.blogspot.com

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150603.1 | Last Updated 22 Oct 2008
Article Copyright 2008 by santosh poojari
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid