/// <summary>
        /// Sends SMS
        /// </summary>
        /// <param name="text">SMS text</param>
        /// <returns>Result</returns>
        public bool SendSms(string text)
        {
            try
            {
                var emailAccount = _emailAccountService.GetEmailAccountById(_emailAccountSettings.DefaultEmailAccountId);
                if (emailAccount == null)
                {
                    emailAccount = _emailAccountService.GetAllEmailAccounts().FirstOrDefault();
                }

                var queuedEmail = new QueuedEmail()
                {
                    Priority       = 5,
                    From           = emailAccount.Email,
                    FromName       = emailAccount.DisplayName,
                    To             = _verizonSettings.Email,
                    ToName         = string.Empty,
                    Subject        = _storeSettings.StoreName,
                    Body           = text,
                    CreatedOnUtc   = DateTime.UtcNow,
                    EmailAccountId = emailAccount.Id
                };

                _queuedEmailService.InsertQueuedEmail(queuedEmail);

                return(true);
            }
            catch (Exception ex)
            {
                _logger.Error(ex.Message, ex);
                return(false);
            }
        }
Beispiel #2
0
        public IActionResult Edit(string id)
        {
            var email = _queuedEmailService.GetQueuedEmailById(id);

            if (email == null)
            {
                //No email found with the specified id
                return(RedirectToAction("List"));
            }

            var model = email.ToModel();

            model.PriorityName     = email.Priority.GetLocalizedEnum(_localizationService, _workContext);
            model.CreatedOn        = _dateTimeHelper.ConvertToUserTime(email.CreatedOnUtc, DateTimeKind.Utc);
            model.EmailAccountName = _emailAccountService.GetEmailAccountById(email.EmailAccountId).DisplayName;
            if (email.SentOnUtc.HasValue)
            {
                model.SentOn = _dateTimeHelper.ConvertToUserTime(email.SentOnUtc.Value, DateTimeKind.Utc);
            }
            if (email.DontSendBeforeDateUtc.HasValue)
            {
                model.DontSendBeforeDate = _dateTimeHelper.ConvertToUserTime(email.DontSendBeforeDateUtc.Value, DateTimeKind.Utc);
            }
            else
            {
                model.SendImmediately = true;
            }

            return(View(model));
        }
        public ActionResult Details(string id)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageMessageContactForm))
            {
                return(AccessDeniedView());
            }

            var contactform = _contactUsService.GetContactUsById(id);

            if (contactform == null)
            {
                return(RedirectToAction("List"));
            }

            var model = contactform.ToModel();

            model.CreatedOn = _dateTimeHelper.ConvertToUserTime(contactform.CreatedOnUtc, DateTimeKind.Utc);
            var store = _storeService.GetStoreById(contactform.StoreId);

            model.Store = store != null ? store.Name: "-empty-";
            var email = _emailAccountService.GetEmailAccountById(contactform.EmailAccountId);

            model.EmailAccountName = email != null ? email.DisplayName : "-empty-";
            return(View(model));
        }
Beispiel #4
0
        private void SendAlertToEmail(Log log)
        {
            try
            {
                if (log.LogLevel == LogLevel.Debug ||
                    (log.PageUrl.Contains("localhost") && !log.PageUrl.Contains("WebDriver")) ||                      // can be The HTTP request to the remote WebDriver server for URL http://localhost:52410/session/695f07f1-7d4e-43a2-83b5-817a8e0c0e83/elements timed out after 60 seconds.
                    String.IsNullOrEmpty(log.IpAddress) ||
                    log.ShortMessage.Contains("was not found or does not implement IController"))
                {
                    return;
                }

                var emailAccount = _emailAccountService.GetEmailAccountById(_emailAccountSettings.DefaultEmailAccountId);
                if (emailAccount == null)
                {
                    throw new NopException("Email account could not be loaded");
                }


                var    from    = new MailAddress(emailAccount.Email, emailAccount.DisplayName);
                var    to      = new MailAddress(emailAccount.Email);
                string subject = "Shop has exception";
                string body    = log.ShortMessage;

                _emailSender.SendEmail(emailAccount, subject, body, from, to);
            }
            catch (Exception)
            {
            }
        }
Beispiel #5
0
        /// <summary>
        /// Create a new SMTP client for a specific email account
        /// </summary>
        /// <param name="emailAccount">Email account to use. If null, then would be used EmailAccount by default</param>
        /// <returns>An SMTP client that can be used to send email messages</returns>
        public virtual SmtpClient Build(EmailAccount emailAccount = null)
        {
            if (emailAccount is null)
            {
                emailAccount = _emailAccountService.GetEmailAccountById(_emailAccountSettings.DefaultEmailAccountId)
                               ?? throw new NopException("Email account could not be loaded");
            }

            var client = new SmtpClient();

            try
            {
                client.Connect(
                    emailAccount.Host,
                    emailAccount.Port,
                    emailAccount.EnableSsl ? SecureSocketOptions.SslOnConnect : SecureSocketOptions.StartTlsWhenAvailable
                    );

                client.Authenticate(emailAccount.UseDefaultCredentials ?
                                    CredentialCache.DefaultNetworkCredentials :
                                    new NetworkCredential(emailAccount.Username, emailAccount.Password));

                return(client);
            }
            catch (Exception ex)
            {
                client.Dispose();
                throw new NopException(ex.Message, ex);
            }
        }
        /// <summary>
        /// Get EmailAccount to use with a message templates
        /// </summary>
        /// <param name="messageTemplate">Message template</param>
        /// <param name="languageId">Language identifier</param>
        /// <returns>EmailAccount</returns>
        protected virtual EmailAccount GetEmailAccountOfMessageTemplate(MessageTemplate messageTemplate, Guid languageId)
        {
            var emailAccount = (_emailAccountService.GetEmailAccountById(messageTemplate.EmailAccountId) ?? _emailAccountService.GetEmailAccountById(_emailAccountSettings.DefaultEmailAccountId)) ??
                               _emailAccountService.GetAllEmailAccounts().FirstOrDefault();

            return(emailAccount);
        }
        protected EmailAccount GetEmailAccountOfMessageTemplate(MessageTemplate messageTemplate, int languageId)
        {
            var emailAccounId = messageTemplate.GetLocalized(mt => mt.EmailAccountId, languageId);
            var emailAccount  = _emailAccountService.GetEmailAccountById(emailAccounId);

            if (emailAccount == null)
            {
                emailAccount = _emailAccountService.GetEmailAccountById(_emailAccountSettings.DefaultEmailAccountId);
            }
            if (emailAccount == null)
            {
                emailAccount = _emailAccountService.GetAllEmailAccounts().FirstOrDefault();
            }

            return(emailAccount);
        }
Beispiel #8
0
        private JsonResult SendToEmail(string toEmail, string subject, string body)
        {
            try
            {
                var emailAccount = _emailAccountService.GetEmailAccountById(_liveChatSettings.SelectedEmailAccountId);

                if (emailAccount == null)
                {
                    return(this.Json((object)new
                    {
                        result = false,
                        message = EngineContext.Current.Resolve <ILocalizationService>().GetResource("Plugins.Widgets.LiveChat.Email.EmailNotSent")
                    }, JsonRequestBehavior.AllowGet));
                }

                string fromEmail     = emailAccount.Email;
                string toDisplayName = emailAccount.DisplayName;
                _emailSender.SendEmail(emailAccount, subject, body, fromEmail, toDisplayName, toEmail, null);
            }
            catch
            {
            }

            return(this.Json((object)new
            {
                result = true,
                message = EngineContext.Current.Resolve <ILocalizationService>().GetResource("Plugins.Widgets.LiveChat.Email.EmailWasSent")
            }, JsonRequestBehavior.AllowGet));
        }
Beispiel #9
0
        public void SendNewsPublicationNotification(NewsItem newItem)
        {
            if (newItem == null)
            {
                throw new ArgumentNullException("new item");
            }
            var account  = _emailAccountService.GetEmailAccountById(_emailAccountSettings.DefaultEmailAccountId);
            var customer = newItem.Customer;
            var template = _messageTemplateService.GetMessageTemplateByName("NewPublishing");

            template.Subject = template.GetLocalized(x => x.Subject, newItem.LanguageId);
            template.Body    = template.GetLocalized(x => x.Body, newItem.LanguageId);
            var tokens = new List <Token>();

            _mesageTokenProvider.AddNewPublishingToken(tokens, newItem);
            _mesageTokenProvider.AddStoreTokens(tokens);
            template.Subject = _tokenizer.Replace(template.Subject, tokens, false);
            template.Body    = _tokenizer.Replace(template.Body, tokens, false);
            var email = new QueuedEmail()
            {
                Priority       = 3,
                From           = account.Email,
                FromName       = account.DisplayName,
                To             = customer.Email,
                Subject        = template.Subject,
                Body           = template.Body,
                CreatedOnUtc   = DateTime.UtcNow,
                EmailAccountId = account.Id
            };

            _queuedEmailService.InsertQueuedEmail(email);
        }
Beispiel #10
0
        public ActionResult ContactUsSend(ContactUsModel model, bool captchaValid)
        {
            //validate CAPTCHA
            if (_captchaSettings.Enabled && _captchaSettings.ShowOnContactUsPage && !captchaValid)
            {
                ModelState.AddModelError("", _localizationService.GetResource("Common.WrongCaptcha"));
            }

            if (ModelState.IsValid)
            {
                string email    = model.Email.Trim();
                string fullName = model.FullName;
                string subject  = string.Format(_localizationService.GetResource("ContactUs.EmailSubject"), _storeInformationSettings.StoreName);

                var emailAccount = _emailAccountService.GetEmailAccountById(_emailAccountSettings.DefaultEmailAccountId);
                if (emailAccount == null)
                {
                    emailAccount = _emailAccountService.GetAllEmailAccounts().FirstOrDefault();
                }

                string from     = null;
                string fromName = null;
                string body     = Core.Html.HtmlHelper.FormatText(model.Enquiry, false, true, false, false, false, false);
                //required for some SMTP servers
                if (_commonSettings.UseSystemEmailForContactUsForm)
                {
                    from     = emailAccount.Email;
                    fromName = emailAccount.DisplayName;
                    body     = string.Format("<strong>From</strong>: {0} - {1}<br /><br />{2}",
                                             Server.HtmlEncode(fullName),
                                             Server.HtmlEncode(email), body);
                }
                else
                {
                    from     = email;
                    fromName = fullName;
                }
                _queuedEmailService.InsertQueuedEmail(new QueuedEmail()
                {
                    From           = from,
                    FromName       = fromName,
                    To             = emailAccount.Email,
                    ToName         = emailAccount.DisplayName,
                    Priority       = 5,
                    Subject        = subject,
                    Body           = body,
                    CreatedOnUtc   = DateTime.UtcNow,
                    EmailAccountId = emailAccount.Id
                });

                model.SuccessfullySent = true;
                model.Result           = _localizationService.GetResource("ContactUs.YourEnquiryHasBeenSent");
                return(View(model));
            }

            model.DisplayCaptcha = _captchaSettings.Enabled && _captchaSettings.ShowOnContactUsPage;
            return(View(model));
        }
        public IActionResult SendTestEmail(CampaignModel model)
        {
            var campaign = _campaignService.GetCampaignById(model.Id);

            if (campaign == null)
            {
                //No campaign found with the specified id
                return(RedirectToAction("List"));
            }

            model = _campaignViewModelService.PrepareCampaignModel(model);
            try
            {
                var emailAccount = _emailAccountService.GetEmailAccountById(_emailAccountSettings.DefaultEmailAccountId);
                if (emailAccount == null)
                {
                    throw new GrandException("Email account could not be loaded");
                }


                var subscription = _newsLetterSubscriptionService.GetNewsLetterSubscriptionByEmailAndStoreId(model.TestEmail, _storeContext.CurrentStore.Id);
                if (subscription != null)
                {
                    //there's a subscription. let's use it
                    var subscriptions = new List <NewsLetterSubscription>();
                    subscriptions.Add(subscription);
                    _campaignService.SendCampaign(campaign, emailAccount, subscriptions);
                }
                else
                {
                    //no subscription found
                    _campaignService.SendCampaign(campaign, emailAccount, model.TestEmail);
                }

                SuccessNotification(_localizationService.GetResource("Admin.Promotions.Campaigns.TestEmailSentToCustomers"), false);
                return(View(model));
            }
            catch (Exception exc)
            {
                ErrorNotification(exc, false);
            }

            //If we got this far, something failed, redisplay form
            return(View(model));
        }
Beispiel #12
0
        public ActionResult Contacts(Nop.Web.Areas.MiniSite.Models.Common.ContactUsModel model, bool captchaValid = true)
        {
            if (ModelState.IsValid)
            {
                string email     = model.Email.Trim();
                string fullName  = model.FullName;
                string StoreName = _workContext.CurrentMiniSite.MiniSiteLayout.RootTitle;
                string subject   = string.Format(_localizationService.GetResource("ContactUs.EmailSubject"), StoreName);

                var emailAccount = _emailAccountService.GetEmailAccountById(_emailAccountSettings.DefaultEmailAccountId);
                if (emailAccount == null)
                {
                    emailAccount = _emailAccountService.GetAllEmailAccounts().FirstOrDefault();
                }

                string from     = null;
                string fromName = null;
                string body     = Core.Html.HtmlHelper.FormatText(model.Enquiry, false, true, false, false, false, false);
                //required for some SMTP servers
                if (_commonSettings.UseSystemEmailForContactUsForm)
                {
                    from     = emailAccount.Email;
                    fromName = emailAccount.DisplayName;
                    body     = string.Format("<strong>From</strong>: {0} - {1}<br />Company: {3} <br /><br />{2}",
                                             Server.HtmlEncode(fullName),
                                             Server.HtmlEncode(email), body, model.Company);
                }
                else
                {
                    from     = email;
                    fromName = fullName;
                }
                _queuedEmailService.InsertQueuedEmail(new QueuedEmail()
                {
                    From           = from,
                    FromName       = fromName,
                    To             = _workContext.CurrentMiniSite.ContactEmail ?? _workContext.CurrentMiniSite.Customer.Email,
                    ToName         = _workContext.CurrentMiniSite.Customer.Username,
                    Priority       = 5,
                    Subject        = subject,
                    Body           = body,
                    CreatedOnUtc   = DateTime.UtcNow,
                    EmailAccountId = emailAccount.Id
                });

                model.SuccessfullySent = true;
                model.Result           = _localizationService.GetResource("ContactUs.YourEnquiryHasBeenSent");
                model.Company          = null;
                model.Email            = null;
                model.Enquiry          = null;
                model.FullName         = null;

                //activity log
                return(View("Contacts", model));
            }
            return(View("Contacts", model));
        }
        public ActionResult ContactUsSend(ContactUsModel model)
        {
            if (ModelState.IsValid)
            {
                string email    = model.Email.Trim();
                string fullName = model.FullName;
                string subject  = string.Format("{0}. {1}", _storeInformationSettings.StoreName, "Contact us");

                var emailAccount = _emailAccountService.GetEmailAccountById(_emailAccountSettings.DefaultEmailAccountId);

                string from     = null;
                string fromName = null;
                string body     = Core.Html.HtmlHelper.FormatText(model.Enquiry, false, true, false, false, false, false);

                if (_commonSettings.UseSystemEmailForContactUsForm)
                {
                    from     = emailAccount.Email;
                    fromName = emailAccount.DisplayName;
                    body     = string.Format("<b>From</b>: {0} - {1}<br /><br />{2}",
                                             Server.HtmlEncode(fullName),
                                             Server.HtmlEncode(email), body);
                }
                else
                {
                    from     = email;
                    fromName = fullName;
                }
                _queuedEmailService.InsertQueuedEmail(new QueuedEmail()
                {
                    From           = from,
                    FromName       = fromName,
                    To             = emailAccount.Email,
                    ToName         = emailAccount.DisplayName,
                    Priority       = 5,
                    Subject        = subject,
                    Body           = body,
                    CreatedOnUtc   = DateTime.UtcNow,
                    EmailAccountId = emailAccount.Id
                });

                return(Json(new { SuccessfullySent = true, Result = _localizationService.GetResource("ContactUs.YourEnquiryHasBeenSent") }));
            }


            var errors = new List <string>();

            foreach (var modelState in ModelState.Values)
            {
                foreach (var error in modelState.Errors)
                {
                    errors.Add(error.ErrorMessage);
                }
            }
            return(Json(new { SuccessfullySent = false, Result = errors.FirstOrDefault() }));
        }
        public virtual void AddStoreTokens(IList <Token> tokens, Store store)
        {
            tokens.Add(new Token("Store.Name", store.Name));
            tokens.Add(new Token("Store.URL", store.Url, true));
            var defaultEmailAccount = _emailAccountService.GetEmailAccountById(_emailAccountSettings.DefaultEmailAccountId);

            if (defaultEmailAccount == null)
            {
                defaultEmailAccount = _emailAccountService.GetAllEmailAccounts().FirstOrDefault();
            }
            tokens.Add(new Token("Store.Email", defaultEmailAccount.Email));
        }
        public ActionResult List(string id)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageEmailAccounts))
            {
                return(AccessDeniedView());
            }

            //mark as default email account (if selected)
            if (!String.IsNullOrEmpty(id))
            {
                int defaultEmailAccountId = Convert.ToInt32(id);
                var defaultEmailAccount   = _emailAccountService.GetEmailAccountById(defaultEmailAccountId);
                if (defaultEmailAccount != null)
                {
                    _emailAccountSettings.DefaultEmailAccountId = defaultEmailAccountId;
                    _settingService.SaveSetting(_emailAccountSettings);
                }
            }

            return(View());
        }
Beispiel #16
0
 public HttpResponseMessage GetEmailById(HttpRequestMessage request, int id)
 {
     return(CreateHttpResponse(request, () =>
     {
         HttpResponseMessage response = request.CreateErrorResponse(HttpStatusCode.NotFound, "No items found");
         if (true)
         {
             var emailAccount = _emailAccountService.GetEmailAccountById(id);
             if (emailAccount == null)
             {
                 //No email account found with the specified id
                 Url.Route("EmailList", null);
                 string uri = Url.Link("EmailList", null);
                 response.Headers.Location = new Uri(uri);
                 return response;
             }
             response = request.CreateResponse <EmailAccountVM>(HttpStatusCode.OK, emailAccount.ToModel());
         }
         else
         {
             response = AccessDeniedView(request);
             //response = request.CreateResponse(HttpStatusCode.Unauthorized, "Unauthorized user");
         }
         return response;
     }));
 }
        /// <summary>
        /// Get EmailAccount to use with a message templates
        /// </summary>
        /// <param name="messageTemplate">Message template</param>
        /// <param name="languageId">Language identifier</param>
        /// <returns>EmailAccount</returns>
        protected virtual EmailAccount GetEmailAccountOfMessageTemplate(MessageTemplate messageTemplate, int languageId)
        {
            //var emailAccountId = _localizationService.GetLocalized(messageTemplate, mt => mt.EmailAccountId, languageId);
            //some 0 validation (for localizable "Email account" dropdownlist which saves 0 if "Standard" value is chosen)
            //if (emailAccountId == 0)
            //    emailAccountId = messageTemplate.EmailAccountId;
            var emailAccountId = messageTemplate.EmailAccountId;

            var emailAccount = (_emailAccountService.GetEmailAccountById(emailAccountId) ?? _emailAccountService.GetEmailAccountById(_emailAccountSettings.DefaultEmailAccountId)) ??
                               _emailAccountService.GetAllEmailAccounts().FirstOrDefault();

            return(emailAccount);
        }
        public void SendEmail(string orderId, string firstName, string email)
        {
            var emailAccount = _emailAccountService.GetEmailAccountById(_emailAccountSettings.DefaultEmailAccountId);

            if (emailAccount != null)
            {
                var subject = "Meedo - Important Payment failed in Instamojo";
                var body    = $"Hi, \n Payment been failed for the genuine payment made by the customer. Please be in touch with customer as soon as possible.\n" +
                              $"OrderId - {orderId}\n CustomerName - {firstName}\n " +
                              $"CustomerEmailAddress - {email}\n";
                _emailSender.SendEmail(emailAccount, subject, body, emailAccount.Email, emailAccount.DisplayName, "*****@*****.**", null);
            }
        }
        public virtual async Task <ContactFormModel> PrepareContactFormModel(ContactUs contactUs)
        {
            var model = contactUs.ToModel();

            model.CreatedOn = _dateTimeHelper.ConvertToUserTime(contactUs.CreatedOnUtc, DateTimeKind.Utc);
            var store = await _storeService.GetStoreById(contactUs.StoreId);

            model.Store = store != null ? store.Shortcut : "-empty-";
            var email = await _emailAccountService.GetEmailAccountById(contactUs.EmailAccountId);

            model.EmailAccountName = email != null ? email.DisplayName : "-empty-";
            return(model);
        }
Beispiel #20
0
        public virtual void AddSiteTokens(IList <Token> tokens)
        {
            tokens.Add(new Token("Site.Name", _siteSettings.Name));
            tokens.Add(new Token("Site.URL", _siteSettings.Url, true));
            var defaultEmailAccount = _emailAccountService.GetEmailAccountById(_emailAccountSettings.DefaultEmailAccountId);

            if (defaultEmailAccount == null)
            {
                defaultEmailAccount = _emailAccountService.GetAllEmailAccounts().FirstOrDefault();
            }
            tokens.Add(new Token("Site.SupplierIdentification", GetSupplierIdentification(), true));
            tokens.Add(new Token("Site.Email", defaultEmailAccount.Email));
        }
        /// <summary>
        /// Get EmailAccount to use with a message templates
        /// </summary>
        /// <param name="messageTemplate">Message template</param>
        /// <param name="languageId">Language identifier</param>
        /// <returns>EmailAccount</returns>
        protected virtual EmailAccount GetEmailAccountOfMessageTemplate(MessageTemplate messageTemplate)
        {
            var emailAccountId = messageTemplate.EmailAccountId;

            //some 0 validation (for localizable "Email account" dropdownlist which saves 0 if "Standard" value is chosen)
            if (emailAccountId == 0)
            {
                emailAccountId = messageTemplate.EmailAccountId;
            }

            var emailAccount = _emailAccountService.GetEmailAccountById(emailAccountId);

            if (emailAccount == null)
            {
                emailAccount = _emailAccountService.GetEmailAccountById(_emailAccountSettings.DefaultEmailAccountId);
            }
            if (emailAccount == null)
            {
                emailAccount = _emailAccountService.GetAllEmailAccounts().FirstOrDefault();
            }
            return(emailAccount);
        }
Beispiel #22
0
        public void SendNewRequestEmail(int requestId, int languageId)
        {
            var request  = _requestService.GetRequestById(requestId);
            var template = _messageTemplateService.GetMessageTemplateByName("ResponceNew");

            template.Subject = template.GetLocalized(x => x.Subject, languageId, false, false);
            template.Body    = template.GetLocalized(x => x.Body, languageId, false, false);
            //template
            var tokens = new List <Token>();

            _messageTokenProvider.AddProductTokens(tokens, _productService.GetProductById(request.ProductId), languageId);
            _messageTokenProvider.AddStoreTokens(tokens);
            _messageTokenProvider.AddNewRequestTokens(tokens, request, languageId);
            string subject = _tokenizer.Replace(template.Subject, tokens, true);
            string body    = _tokenizer.Replace(template.Body, tokens, true);

            string email        = request.Product.Customer.Email;
            var    emailAccount = _emailAccountService.GetEmailAccountById(_emailAccountSettings.DefaultEmailAccountId);
            var    from         = new MailAddress(emailAccount.Email, emailAccount.DisplayName);
            var    to           = new MailAddress(email);

            _emailSender.SendEmail(emailAccount, subject, body, from, to);
        }
Beispiel #23
0
        public void SendEmail(string errorMessage, PostProcessPaymentRequest postProcessPaymentRequest)
        {
            var emailAccount = _emailAccountService.GetEmailAccountById(_emailAccountSettings.DefaultEmailAccountId);

            if (emailAccount != null)
            {
                var subject = "Meedo - Important Payment failed in Payu";
                var body    = $"Hi, \n Payment been failed for the genuine payment made by the customer. Please be in touch with customer as soon as possible.\n" +
                              $"OrderId - {postProcessPaymentRequest.Order.Id}\n CustomerName - {postProcessPaymentRequest.Order.BillingAddress.FirstName}\n " +
                              $"CustomerEmailAddress - {postProcessPaymentRequest.Order.BillingAddress.Email}\n CustomerPhoneNumber - {postProcessPaymentRequest.Order.BillingAddress.PhoneNumber}\n" +
                              $"Exception - {errorMessage}";
                _emailSender.SendEmail(emailAccount, subject, body, emailAccount.Email, emailAccount.DisplayName, "*****@*****.**", null);
            }
        }
Beispiel #24
0
        public ActionResult SendTestEmail(CampaignModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageCampaigns))
            {
                return(AccessDeniedView());
            }

            var campaign = _campaignService.GetCampaignById(model.Id);

            if (campaign == null)
            {
                //No campaign found with the specified id
                return(RedirectToAction("List"));
            }


            model.AllowedTokens = FormatTokens(_messageTokenProvider.GetListOfCampaignAllowedTokens());

            try
            {
                var emailAccount = _emailAccountService.GetEmailAccountById(_emailAccountSettings.DefaultEmailAccountId);
                if (emailAccount == null)
                {
                    throw new NopException("Email account could not be loaded");
                }
                _campaignService.SendCampaign(campaign, emailAccount, model.TestEmail);
                SuccessNotification(_localizationService.GetResource("Admin.Promotions.Campaigns.TestEmailSentToCustomers"), false);
                return(View(model));
            }
            catch (Exception exc)
            {
                ErrorNotification(exc, false);
            }

            //If we got this far, something failed, redisplay form
            return(View(model));
        }
        public ActionResult Contact(string email, string phone, string comments)
        {
            MailMessage mail = new MailMessage();
            // SmtpClient SmtpServer = new SmtpClient("mail.2xprime.com");

            // SmtpServer.Port = 25;
            //SmtpServer.EnableSsl = true;
            string bodyForAccDept = string.Empty;

            mail.Subject = "Petal Price";


            StringBuilder stringBuilder = new StringBuilder(mail.Body);

            stringBuilder.Append("<html><body>");
            stringBuilder.Append("Hello, ");
            stringBuilder.Append("<br/>");
            stringBuilder.Append("<br/>");
            stringBuilder.Append("Please contact to following person.");
            stringBuilder.Append("<br/>");
            stringBuilder.Append("Phone Number:" + phone); //form.phoneNumber
            stringBuilder.Append("<br/>");
            stringBuilder.Append("Email ID: " + email);
            stringBuilder.Append("<br/>");
            stringBuilder.Append("Comments: " + comments);
            stringBuilder.Append("<br/>");
            stringBuilder.Append("<br/>");
            stringBuilder.Append("<br/>");

            stringBuilder.Append("Thanks, ");
            stringBuilder.Append("<br/>");
            stringBuilder.Append("Petal Price.");
            stringBuilder.Append("</body></html>");

            //SmtpServer.UseDefaultCredentials = false;
            //SmtpServer.Credentials = new System.Net.NetworkCredential("*****@*****.**", "Prime@123");
            //mail.From = new MailAddress("*****@*****.**");
            // mail.To.Add(new MailAddress("*****@*****.**"));
            mail.Body = stringBuilder.ToString();
            string adminEmail = _services.WorkContext.CurrentCustomer.Email;

            var emailAccount = _emailAccountService.GetEmailAccountById(1); //replace it with Admin Id in future
            var msg          = new EmailMessage(adminEmail, mail.Subject, mail.Body, emailAccount.Email);

            _emailSender.SendEmail(new SmtpContext(emailAccount), msg);

            // SmtpServer.Send(mail);
            return(Json(true, JsonRequestBehavior.AllowGet));
        }
Beispiel #26
0
        public ActionResult List(string id)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageEmailAccounts))
            {
                return(AccessDeniedView());
            }

            //mark as default email account (if selected)
            if (!String.IsNullOrEmpty(id))
            {
                int defaultEmailAccountId = Convert.ToInt32(id);
                var defaultEmailAccount   = _emailAccountService.GetEmailAccountById(defaultEmailAccountId);
                if (defaultEmailAccount != null)
                {
                    _emailAccountSettings.DefaultEmailAccountId = defaultEmailAccountId;
                    _settingService.SaveSetting(_emailAccountSettings);
                }
            }

            var emailAccountModels = _emailAccountService.GetAllEmailAccounts()
                                     .Select(x => x.ToModel())
                                     .ToList();

            foreach (var eam in emailAccountModels)
            {
                eam.IsDefaultEmailAccount = eam.Id == _emailAccountSettings.DefaultEmailAccountId;
            }

            var gridModel = new GridModel <EmailAccountModel>
            {
                Data  = emailAccountModels,
                Total = emailAccountModels.Count()
            };

            return(View(gridModel));
        }
Beispiel #27
0
        public virtual void AddStoreTokens(IList <Token> tokens, Store store)
        {
            tokens.Add(new Token("Store.Name", store.GetLocalized(x => x.Name)));
            tokens.Add(new Token("Store.URL", store.Url, true));
            var defaultEmailAccount = _emailAccountService.GetEmailAccountById(_emailAccountSettings.DefaultEmailAccountId);

            if (defaultEmailAccount == null)
            {
                defaultEmailAccount = _emailAccountService.GetAllEmailAccounts().FirstOrDefault();
            }
            tokens.Add(new Token("Store.Email", defaultEmailAccount.Email));

            //event notification
            _eventPublisher.EntityTokensAdded(store, tokens);
        }
Beispiel #28
0
        /// <summary>
        /// Executes a task
        /// </summary>
        public virtual void Execute()
        {
            lock (_lock)
            {
                var maxTries     = 3;
                var queuedEmails = _queuedEmailService.SearchEmails(null, null, null, null, true, true, maxTries, false, 0, 500);
                foreach (var queuedEmail in queuedEmails)
                {
                    var bcc = String.IsNullOrWhiteSpace(queuedEmail.Bcc)
                                ? null
                                : queuedEmail.Bcc.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                    var cc = String.IsNullOrWhiteSpace(queuedEmail.CC)
                                ? null
                                : queuedEmail.CC.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);

                    try
                    {
                        var emailAccount = _emailAccountService.GetEmailAccountById(queuedEmail.EmailAccountId);
                        _emailSender.SendEmail(emailAccount,
                                               queuedEmail.Subject,
                                               queuedEmail.Body,
                                               queuedEmail.From,
                                               queuedEmail.FromName,
                                               queuedEmail.To,
                                               queuedEmail.ToName,
                                               queuedEmail.ReplyTo,
                                               queuedEmail.ReplyToName,
                                               bcc,
                                               cc,
                                               queuedEmail.AttachmentFilePath,
                                               queuedEmail.AttachmentFileName,
                                               queuedEmail.AttachedDownloads);

                        queuedEmail.SentOnUtc = DateTime.UtcNow;
                    }
                    catch (Exception exc)
                    {
                        _logger.Error(string.Format("Error sending e-mail. {0}", exc.Message), exc);
                    }
                    finally
                    {
                        queuedEmail.SentTries = queuedEmail.SentTries + 1;
                        _queuedEmailService.UpdateQueuedEmail(queuedEmail);
                    }
                }
            }
        }
Beispiel #29
0
        public IActionResult MarkAsDefaultEmail(string id)
        {
            var defaultEmailAccount = _emailAccountService.GetEmailAccountById(id);

            if (defaultEmailAccount != null)
            {
                _emailAccountSettings.DefaultEmailAccountId = defaultEmailAccount.Id;
                _settingService.SaveSetting(_emailAccountSettings);
            }
            return(RedirectToAction("List"));
        }
Beispiel #30
0
        protected EmailAccount GetEmailAccountOfMessageTemplate(MessageTemplate messageTemplate, int languageId)
        {
            var accountId = messageTemplate.GetLocalized(x => x.EmailAccountId, languageId);
            var account   = _emailAccountService.GetEmailAccountById(accountId);

            if (account == null)
            {
                account = _emailAccountService.GetDefaultEmailAccount();
            }

            if (account == null)
            {
                throw new SmartException(T("Common.Error.NoEmailAccount"));
            }

            return(account);
        }