Example #1
0
        public string UpdateSenderEmailAccount(SenderEmailAccountForm senderEmailAccountForm)
        {
            DefaultController defaultController = new DefaultController(SenderEmailAccountService.Keywords.SENDEREMAILACCOUNT);

            defaultController.FormValidator = new SenderEmailAccountFormValidator();

            OperationResult result = defaultController.Update(senderEmailAccountForm);

            return(Serializer.Json.Serialize(result));
        }
        public OperationResult SendEmailByTag(SendEmailForm sendEmailForm)
        {
            SenderEmailAccountForm senderEmailAccount = GetSenderEmailAccountByTag(sendEmailForm.Tag);
            EmailTemplateForm      emailTemplate      = GetEmailTemplateByTag(sendEmailForm.Tag);

            if (senderEmailAccount != null && emailTemplate != null)
            {
                emailTemplate.EmailContent = ReplaceContent(emailTemplate.EmailContent, sendEmailForm.KeyValues);
                emailTemplate.EmailSubject = ReplaceContent(emailTemplate.EmailSubject, sendEmailForm.KeyValues);

                return(SaveToDatabase(senderEmailAccount, emailTemplate, sendEmailForm));
            }

            return(new OperationResult(false, "No sender and email template defined for tag = '" + sendEmailForm.Tag + "'"));
        }
        protected virtual SenderEmailAccountForm GetSenderEmailAccountByTag(string tag)
        {
            ISenderEmailAccountBusinessService senderEmailAccountService = new SenderEmailAccountBusinessService();
            OperationResult result = senderEmailAccountService.FindAllByTag(tag);
            List <object>   senderEmailAccountList = (List <object>)result.Data;

            if (senderEmailAccountList.Count > 0)
            {
                object obj = senderEmailAccountList[0];
                SenderEmailAccountForm senderEmailAccountForm = new SenderEmailAccountForm();
                SenderEmailAccountFormDataConverter converter = new SenderEmailAccountFormDataConverter();
                converter.PopulateForm(obj, senderEmailAccountForm);
                return(senderEmailAccountForm);
            }
            return(null);
        }
Example #4
0
        public ValidationResult Validate(DataForm form)
        {
            ValidationResult       result = new ValidationResult(true);
            SenderEmailAccountForm senderEmailAccountForm = (SenderEmailAccountForm)form;

            if (senderEmailAccountForm.SenderName.Length == 0)
            {
                result.Result       = false;
                result.ErrorMessage = "Sender Name can not be empty";
            }

            if (senderEmailAccountForm.SenderEmail.Length == 0)
            {
                result.Result       = false;
                result.ErrorMessage = "Sender Email can not be empty";
            }

            if (senderEmailAccountForm.SmtpServer.Length == 0)
            {
                result.Result       = false;
                result.ErrorMessage = "Smtp Server can not be empty";
            }

            if (senderEmailAccountForm.EmailAccount.Length == 0)
            {
                result.Result       = false;
                result.ErrorMessage = "Email Account can not be empty";
            }

            if (senderEmailAccountForm.EmailAccountPassword.Length == 0)
            {
                result.Result       = false;
                result.ErrorMessage = "Email Account Password can not be empty";
            }

            return(result);
        }
        protected virtual OperationResult SaveToDatabase(SenderEmailAccountForm senderEmailAccount, EmailTemplateForm emailTemplate, SendEmailForm sendMailForm)
        {
            object obj = Factory.Create <object>("EmailSent", ClassType.clsTypeDataModel);

            obj.GetType().GetProperty("SenderName").SetValue(obj, senderEmailAccount.SenderName, null);
            obj.GetType().GetProperty("EmailFrom").SetValue(obj, senderEmailAccount.EmailAccount, null);
            obj.GetType().GetProperty("EmailFromAlias").SetValue(obj, senderEmailAccount.SenderEmail, null);
            obj.GetType().GetProperty("EmailSubject").SetValue(obj, emailTemplate.EmailSubject, null);
            obj.GetType().GetProperty("EmailContent").SetValue(obj, emailTemplate.EmailContent, null);
            obj.GetType().GetProperty("SentDate").SetValue(obj, DateTime.Now, null);
            obj.GetType().GetProperty("EmailTos").SetValue(obj, sendMailForm.To, null);
            obj.GetType().GetProperty("EmailCcs").SetValue(obj, sendMailForm.Cc, null);
            obj.GetType().GetProperty("UserId").SetValue(obj, senderEmailAccount.UserId, null);
            obj.GetType().GetProperty("IsSent").SetValue(obj, 0, null);
            obj.GetType().GetProperty("EmailAccountId").SetValue(obj, senderEmailAccount.IdSender, null);


            EmailSentBusinessService businessService = new EmailSentBusinessService();
            OperationResult          result          = businessService.Add(obj);
            object emailSent = result.Data;

            EmailAttachmentBusinessService bs = new EmailAttachmentBusinessService();

            if (sendMailForm.Attachments != null)
            {
                foreach (EmailAttachment attachment in sendMailForm.Attachments)
                {
                    attachment.EmailSentId = Convert.ToInt64(emailSent.GetType().GetProperty("IdEmailSent").GetValue(emailSent, null));
                    bs.Add(attachment);
                }
            }

            // emailSent.EmailContent = Convert.ToBase64String(Encoding.UTF8.GetBytes(emailSent.EmailContent));
            result.Data = emailSent;
            return(result);
        }