Пример #1
0
        /// <summary>
        /// ทำการกำหนดกางส่งเมลล์ให้ทั้งหมด
        /// ลบรายชื่อผู้ส่งรายชื่อผู้รับ
        /// ลบรายละเอียดเมลล์ทั้งหมด
        /// </summary>
        private void ResetEmail()
        {
            email = new Email();

            mailSender = new Email.MailSender();

            mailReceiverTO.ReceiverAddress = new ArrayList();
            mailReceiverTO.ReceiverName    = new ArrayList();

            mailReceiverCC.ReceiverAddress = new ArrayList();
            mailReceiverCC.ReceiverName    = new ArrayList();

            mailReceiverBCC.ReceiverAddress = new ArrayList();
            mailReceiverBCC.ReceiverName    = new ArrayList();

            MailSubject = "";
            MailBody    = "";
            MailFileAttachmentFullPath = "";
        }
Пример #2
0
        /// <summary>
        /// ทำการกำหนดค่าตาม Default
        /// </summary>
        public EmailService()
        {
            string strMailSMTPServer   = ParameterServices.SMTPMailServer;
            string intMailSMTPPort     = ParameterServices.SMTPPort;
            string strMailSMTPUserName = ParameterServices.SMTPMailUser;
            string strMailSMTPPassword = ParameterServices.SMTPMailPassword;
            string strAdminAddress     = ParameterServices.AdminEmailAddress;
            string strAdminName        = ParameterServices.AdminName;

            email = new Email();

            mailSender = new Email.MailSender();

            mailReceiverTO.ReceiverAddress = new ArrayList();
            mailReceiverTO.ReceiverName    = new ArrayList();

            mailReceiverCC.ReceiverAddress = new ArrayList();
            mailReceiverCC.ReceiverName    = new ArrayList();

            mailReceiverBCC.ReceiverAddress = new ArrayList();
            mailReceiverBCC.ReceiverName    = new ArrayList();

            MailSMTPServer   = strMailSMTPServer;
            MailSMTPPort     = int.Parse(intMailSMTPPort);
            MailSMTPUserName = strMailSMTPUserName;
            MailSMTPPassword = strMailSMTPPassword;

            SetMailSender(strAdminAddress, strAdminName);

            MailSubject = "";
            MailBody    = "";
            MailFileAttachmentFullPath = "";

            MailSendingType    = Email.MailType.TEXT;
            IsMultipleReceiver = true;
        }
Пример #3
0
        public bool SendEmail(EmailDTO emailParam)
        {
            try
            {
                email = new Email();

                mailSender = new Email.MailSender();

                mailReceiverTO.ReceiverAddress = new ArrayList();
                mailReceiverTO.ReceiverName    = new ArrayList();

                mailReceiverCC.ReceiverAddress = new ArrayList();
                mailReceiverCC.ReceiverName    = new ArrayList();

                mailReceiverBCC.ReceiverAddress = new ArrayList();
                mailReceiverBCC.ReceiverName    = new ArrayList();

                SetMailSender(string.IsNullOrEmpty(emailParam.Sender.Email) ? strAdminAddress : emailParam.Sender.Email, string.IsNullOrEmpty(emailParam.Sender.Name) ? strAdminName : emailParam.Sender.Name);

                if (emailParam.MailSendTo != null && emailParam.MailSendTo.Count > 0)
                {
                    foreach (AddMailSendTo itemSendTo in emailParam.MailSendTo)
                    {
                        AddMailTO(itemSendTo.Email, itemSendTo.Name);
                    }
                }

                if (emailParam.MailSendToCC != null && emailParam.MailSendToCC.Count > 0)
                {
                    foreach (AddMailSendToCC itemSendToCC in emailParam.MailSendToCC)
                    {
                        AddMailCC(itemSendToCC.Email, itemSendToCC.Name);
                    }
                }

                if (emailParam.MailSendToBCC != null && emailParam.MailSendToBCC.Count > 0)
                {
                    foreach (AddMailSendToBCC itemSendToBCC in emailParam.MailSendToBCC)
                    {
                        AddMailBCC(itemSendToBCC.Email, itemSendToBCC.Name);
                    }
                }


                email.IsMultipleReceiver = emailParam.IsMultipleReceiver;

                email.mailSMTPServer   = ParameterServices.SMTPMailServer;      //strMailSMTPServer;
                email.mailSMTPPort     = int.Parse(ParameterServices.SMTPPort); //int.Parse(intMailSMTPPort);
                email.mailSMTPUserName = ParameterServices.SMTPMailUser;        //strMailSMTPUserName;
                email.mailSMTPPassword = ParameterServices.SMTPMailPassword;    //strMailSMTPPassword;

                email.mailSubject = emailParam.MailSubject;
                email.mailBody    = emailParam.MailBody;
                email.mailFileAttachmentFullPath = emailParam.MailFileAttachmentFullPath;

                email.mailSender      = mailSender;
                email.mailReceiverTo  = mailReceiverTO;
                email.mailReceiverCC  = mailReceiverCC;
                email.mailReceiverBCC = mailReceiverBCC;

                email.SendingType = emailParam.MailSendingType;

                return(email.Send());
            }
            catch (Exception)
            {
                Spring.Validation.ValidationErrors errors = new Spring.Validation.ValidationErrors();

                errors.AddError("User.Error", new Spring.Validation.ErrorMessage("Email service was failure."));
                throw new ServiceValidationException(errors);
            }
        }