예제 #1
0
 private void SaveEmailMessage(EmailParam objEmail, bool eMailStatus, bool isPrimary, Exception ex = null)
 {
     //TO DO
 }
예제 #2
0
        public bool SendEmailUsingSecondary(EmailParam objEmail)
        {
            byte[] bArray = { };

            string P_SMTP        = objEmail.PrimarySMTP;
            string P_MsgFrom     = objEmail.PrimaryFrom;
            string P_MailFrmUID  = objEmail.PrimaryUserName;
            string P_MailFrmPW   = objEmail.PrimaryPassword;
            int    P_MailFrmPort = objEmail.PrimaryPortNo;
            bool   P_PrimaryUseDefaultCredentials = objEmail.PrimaryUseDefaultCredentials;
            bool   P_PrimaryEnableSsl             = objEmail.PrimaryEnableSsl;

            string S_SMTP        = objEmail.SecondarySMTP;
            string S_MsgFrom     = objEmail.SecondaryFrom;
            string S_MailFrmUID  = objEmail.SecondaryUserName;
            string S_MailFrmPW   = objEmail.SecondaryPassword;
            int    S_MailFrmPort = objEmail.SecondaryPortNo;
            bool   S_PrimaryUseDefaultCredentials = objEmail.SecondaryUseDefaultCredentials;
            bool   S_PrimaryEnableSsl             = objEmail.SecondaryEnableSsl;

            string MsgTo      = string.Empty;
            string ccEmail    = string.Empty;
            string bccEmail   = string.Empty;
            string MsgSubject = string.Empty;
            string MsgBody    = string.Empty;


            MailMessage           msg = new MailMessage();
            MailAddressCollection lst_ToMAC;
            MailAddressCollection lst_CCMAC;
            MailAddressCollection lst_BCCMAC;

            bool bMailSent = false;

            try
            {
                MsgSubject = objEmail.MailSubject;

                MsgBody = objEmail.MailContent;

                msg            = new MailMessage(objEmail.ApplicationName + " <" + objEmail.SecondaryFrom + ">", objEmail.ToEmailAddress, MsgSubject, MsgBody);
                msg.IsBodyHtml = true;

                lst_ToMAC = GetMailAddressList(objEmail.ToEmailAddress);

                foreach (var item in lst_ToMAC)
                {
                    msg.To.Add(item);
                }

                if (!string.IsNullOrEmpty(objEmail.CCEmailAddress))
                {
                    lst_CCMAC = GetMailAddressList(objEmail.CCEmailAddress);

                    foreach (var item in lst_CCMAC)
                    {
                        msg.CC.Add(item);
                    }
                }

                if (!string.IsNullOrEmpty(objEmail.BCCEmailAddress))
                {
                    lst_BCCMAC = GetMailAddressList(objEmail.BCCEmailAddress);
                    foreach (var item in lst_BCCMAC)
                    {
                        msg.Bcc.Add(item);
                    }
                }

                SmtpClient        mailClient = new SmtpClient(S_SMTP, S_MailFrmPort);
                NetworkCredential NetCrd     = new NetworkCredential(S_MsgFrom, S_MailFrmPW);
                mailClient.UseDefaultCredentials = S_PrimaryUseDefaultCredentials;
                mailClient.Credentials           = NetCrd;
                mailClient.EnableSsl             = S_PrimaryEnableSsl;

                mailClient.Send(msg);
                bMailSent = true;
                SaveEmailMessage(objEmail, true, false);
            }
            catch (Exception ex)
            {
                bMailSent = false;
                SaveEmailMessage(objEmail, false, false, ex);
            }
            return(bMailSent);
        }