/// <summary> /// Sends a campaign to specified email /// </summary> /// <param name="campaign">Campaign</param> /// <param name="emailAccount">Email account</param> /// <param name="email">Email</param> public virtual void SendCampaign(Campaign campaign, EmailAccount emailAccount, string email) { if (campaign == null) throw new ArgumentNullException("campaign"); if (emailAccount == null) throw new ArgumentNullException("emailAccount"); var tokens = new List<Token>(); _messageTokenProvider.AddStoreTokens(tokens, _storeContext.CurrentStore); _messageTokenProvider.AddNewsLetterSubscriptionTokens(tokens, new NewsLetterSubscription() { Email = email }); var customer = _customerService.GetCustomerByEmail(email); if (customer != null) _messageTokenProvider.AddCustomerTokens(tokens, customer); string subject = _tokenizer.Replace(campaign.Subject, tokens, false); string body = _tokenizer.Replace(campaign.Body, tokens, true); var to = new EmailAddress(email); var from = new EmailAddress(emailAccount.Email, emailAccount.DisplayName); var msg = new EmailMessage(to, subject, body, from); _emailSender.SendEmail(new SmtpContext(emailAccount), msg); }
public ActionResult SendTestEmail(EmailAccountModel model) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageEmailAccounts)) return AccessDeniedView(); var emailAccount = _emailAccountService.GetEmailAccountById(model.Id); if (emailAccount == null) //No email account found with the specified id return RedirectToAction("List"); try { if (String.IsNullOrWhiteSpace(model.SendTestEmailTo)) throw new SmartException("Enter test email address"); var to = new EmailAddress(model.SendTestEmailTo); var from = new EmailAddress(emailAccount.Email, emailAccount.DisplayName); string subject = _storeContext.CurrentStore.Name + ". Testing email functionality."; string body = "Email works fine."; _emailSender.SendEmail(new SmtpContext(emailAccount), new EmailMessage(to, subject, body, from)); NotifySuccess(_localizationService.GetResource("Admin.Configuration.EmailAccounts.SendTestEmail.Success"), false); } catch (Exception exc) { NotifyError(exc.Message, false); } //If we got this far, something failed, redisplay form return View(model); }