public IHttpActionResult Get(int id) { //get the account var emailTemplate = _emailTemplateService.Get(id); if (emailTemplate == null) { return(NotFound()); } var model = emailTemplate.ToEntityModel(); model.AvailableEmailAccounts = _emailAccountService.Get().ToList().Select(x => { dynamic newObject = new ExpandoObject(); newObject.Name = $"{x.FromName} ({x.Email})"; newObject.Id = x.Id; return(newObject); }).ToList(); model.AvailableMasterTemplates = _emailTemplateService.Get(x => x.IsMaster && x.Id != id).ToList().Select(x => { dynamic newObject = new ExpandoObject(); newObject.Name = x.TemplateName; newObject.Id = x.Id; return(newObject); }).ToList(); return(RespondSuccess(new { EmailTemplate = model })); }
public IHttpActionResult Get([FromUri] EmailAccountGetModel requestModel) { requestModel = requestModel ?? new EmailAccountGetModel(); if (requestModel.Count <= 0) { requestModel.Count = 15; } if (requestModel.Page <= 0) { requestModel.Page = 1; } //get the email accounts var emailAccounts = _emailAccountService.Get(page: requestModel.Page, count: requestModel.Count).ToList(); var model = emailAccounts.Select(x => x.ToEntityModel()); return(RespondSuccess(new { EmailAccounts = model })); }
public IActionResult GetById(int id) { var emailAccount = _emailAccountService.Get(id); if (emailAccount == null) { return(RespondFailure()); } var model = emailAccount;//.ToModel(); //model.Password = _cryptographyService.Encrypt(model.Password); return(RespondSuccess(model)); }
public IActionResult EmailTemplateEditor(int emailTemplateId) { var emailTemplate = emailTemplateId > 0 ? _emailTemplateService.Get(emailTemplateId) : new EmailTemplate(); if (emailTemplate == null) { return(NotFound()); } var model = _modelMapper.Map <EmailTemplateModel>(emailTemplate); if (emailTemplate.ParentEmailTemplate != null) { model.ParentEmailTemplate = _modelMapper.Map <EmailTemplateModel>(emailTemplate.ParentEmailTemplate); } model.EmailAccount = _modelMapper.Map <EmailAccountModel>(emailTemplate.EmailAccount); //available email accounts var emailAccounts = _emailAccountService.Get(x => true).OrderBy(x => x.Email).ToList(); var availableEmailAccounts = SelectListHelper.GetSelectItemList(emailAccounts, x => x.Id, x => x.Email); //available master templates var masterTemplates = _emailTemplateService.Get(x => x.IsMaster).OrderBy(x => x.TemplateName).ToList(); var availableMasterTemplates = SelectListHelper.GetSelectItemList(masterTemplates, x => x.Id, x => x.TemplateName); var isAdminEmailRequired = emailTemplate.TemplateSystemName != null && ((emailTemplate.TemplateSystemName.EndsWith(EmailTemplateNames.AdminSuffix) && emailTemplate.IsSystem) || (emailTemplate.TemplateSystemName.EndsWith(EmailTemplateNames.AdminSuffix))); //available tokens var tokens = _emailTemplateService.GetTemplateTokens(emailTemplate.TemplateSystemName).OrderBy(x => x); return(R.Success.With("emailTemplate", model) .With("availableEmailAccounts", availableEmailAccounts) .With("availableMasterTemplates", availableMasterTemplates) .With("availableTokens", tokens) .With("adminEmailRequired", isAdminEmailRequired) .Result); }
private bool GetMailObjects(EmailMessage emailMessage, out MailMessage mailMessage, out SmtpClient smtpClient) { mailMessage = null; smtpClient = null; //we need an email account var emailAccount = emailMessage.EmailAccount ?? _emailAccountService.Get(_emailSenderSettings.DefaultEmailAccountId) ?? _emailAccountService.FirstOrDefault(x => true); if (emailAccount == null) { _logger.Log <EmailService>(LogLevel.Error, $"Failed to send email. No default email account could be loaded."); return(false); //can't send email without account } var message = new MailMessage(); //from, to, reply to message.From = new MailAddress(emailAccount.Email, emailAccount.FromName); if (emailMessage.Tos == null && emailMessage.Ccs == null && emailMessage.Bccs == null) { throw new EvenCartException("At least one of Tos, CCs or BCCs must be specified to send email"); } if (emailMessage.Tos != null) { foreach (var userInfo in emailMessage.Tos) { message.To.Add(new MailAddress(userInfo.Email, userInfo.Name)); } } if (emailMessage.ReplyTos != null) { foreach (var userInfo in emailMessage.ReplyTos) { message.ReplyToList.Add(new MailAddress(userInfo.Email, userInfo.Name)); } } if (emailMessage.Bccs != null) { foreach (var userInfo in emailMessage.Bccs) { message.Bcc.Add(new MailAddress(userInfo.Email, userInfo.Name)); } } if (emailMessage.Ccs != null) { foreach (var userInfo in emailMessage.Ccs) { message.Bcc.Add(new MailAddress(userInfo.Email, userInfo.Name)); } } //content message.Subject = emailMessage.Subject; message.Body = emailMessage.EmailBody; message.IsBodyHtml = emailMessage.IsEmailBodyHtml; //headers if (emailMessage.Headers != null) { foreach (var header in emailMessage.Headers) { message.Headers.Add(header.Key, header.Value); } } if (emailMessage.Attachments != null) { foreach (var attachment in emailMessage.Attachments) { message.Attachments.Add(attachment); } } //send email var password = _cryptographyService.Decrypt(emailAccount.Password); smtpClient = new SmtpClient { UseDefaultCredentials = emailAccount.UseDefaultCredentials, Host = emailAccount.Host, Port = emailAccount.Port, EnableSsl = emailAccount.UseSsl, Credentials = emailAccount.UseDefaultCredentials ? CredentialCache.DefaultNetworkCredentials : new NetworkCredential(emailAccount.UserName, password) }; mailMessage = message; return(true); }
public EmailAccountItem Get(long id) { return(_emailAccountService.Get(id)); }