Beispiel #1
0
        /// <summary>
        /// Create email queue
        /// </summary>
        /// <param name="emailLog"></param>
        /// <param name="useDefaultAccount"></param>
        /// <returns></returns>
        public ResponseModel CreateEmail(EmailLog emailLog, bool useDefaultAccount = false)
        {
            if (useDefaultAccount || emailLog.EmailAccountId == 0)
            {
                var defaultAccount = _emailAccountService.GetDefaultAccount();
                if (defaultAccount == null)
                {
                    defaultAccount = _emailAccountService.GetAll().FirstOrDefault();
                    if (defaultAccount == null)
                    {
                        return new ResponseModel
                               {
                                   Success = false,
                                   Message = T("EmailLog_Message_MissingDefaultAccount")
                               }
                    }
                    ;
                }

                if (string.IsNullOrEmpty(emailLog.From))
                {
                    emailLog.From = defaultAccount.Email;
                }
                if (string.IsNullOrEmpty(emailLog.FromName))
                {
                    emailLog.FromName = defaultAccount.Email;
                }
                emailLog.EmailAccountId = defaultAccount.Id;
            }

            var logs = new List <EmailSendingLog>
            {
                new EmailSendingLog
                {
                    Time    = DateTime.Now,
                    Message = TFormat("EmailLog_Message_CreateEmailLog", DateTime.UtcNow)
                }
            };

            emailLog.Message = SerializeUtilities.Serialize(logs);

            var response = Insert(emailLog);

            return(response.SetMessage(response.Success
                ? T("EmailLog_Message_CreateSuccessfully")
                : T("EmailLog_Message_CreateFailure")));
        }