Example #1
0
        public void Send(EmailContent objEC)
        {
            try
            {
                MailMessage mailMsg = new MailMessage();
                //From Address
                mailMsg.From = new MailAddress(objEC.FromAddress, "CREDITSCHECK");
                //To Address
                if (objEC.ToAddress.Contains(';'))
                {
                    var _strTo = (from s in objEC.ToAddress.Split(';')
                                  select s).ToList();
                    foreach (string s in _strTo)
                    {
                        mailMsg.To.Add(new MailAddress(s));
                    }
                }
                else
                {
                    mailMsg.To.Add(new MailAddress(objEC.ToAddress));
                }
                //Subject
                mailMsg.Subject = objEC.Subject;
                //Body
                if (objEC.IsEmailTemplate)
                {
                    mailMsg.Body = GenerateEmailBodyFromTemplate(objEC.Body, objEC.TemplateObject);
                }
                else
                {
                    mailMsg.Body = objEC.Body;

                }
                mailMsg.IsBodyHtml = true;
                //Send Mail
                SmtpClient smtpClient = new SmtpClient();
                smtpClient.Send(mailMsg);

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #2
0
        public EmailContent GetEmailTemplatebyID(int ID)
        {
            DataSet ds = new DataSet();
            EmailContent objResponse = new EmailContent();
            try
            {
                SqlParameter[] sqlParams = new SqlParameter[1];
                sqlParams[0] = new SqlParameter("@MAILERID", SqlDbType.Int);
                sqlParams[0].Value = ID;

                ds = CExecuteDataset("USP_GETEMAILSMSTEMPLATE", sqlParams);

                if (ds != null)
                {

                    objResponse.FromAddress = ds.Tables[0].Rows[0]["FROMEMAIL"].ToString();
                    objResponse.Subject = ds.Tables[0].Rows[0]["SUBJECT"].ToString();
                    objResponse.Body = ds.Tables[0].Rows[0]["BODY"].ToString();
                }

            }
            catch (Exception ex)
            {
                InsertWebsiteLog("", "Common.cs", "GetEmailTemplatebyID", "ID=" + ID, ex.ToString());
            }
            return objResponse;
        }