Пример #1
0
        /// <summary>
        /// Sends 'New user' notification message to a application owner
        /// </summary>
        /// <param name="user">User instance</param>
        /// <param name="languageId">Message language identifier</param>
        /// <returns>Queued email identifier</returns>
        public virtual int SendUserRegisteredNotificationMessage(User user, int languageId)
        {
            if (user == null)
            {
                throw new ArgumentNullException("user");
            }

            var application = _sysContext.CurrentApplication;

            languageId = EnsureLanguageIsActive(languageId, application.Id);

            var messageTemplate = GetActiveMessageTemplate(MessageTemplateSystemNames.UserRegisteredNotification, application.Id);

            if (messageTemplate == null)
            {
                return(0);
            }

            //email account
            var emailAccount = GetEmailAccountOfMessageTemplate(messageTemplate, languageId);

            //tokens
            var tokens = new List <Token>();

            _messageTokenProvider.AddApplicationTokens(tokens, application, emailAccount);
            _messageTokenProvider.AddUserTokens(tokens, user);

            //event notification
            _eventPublisher.MessageTokensAdded(messageTemplate, tokens);

            var toEmail = emailAccount.Email;
            var toName  = emailAccount.DisplayName;

            return(SendNotification(messageTemplate, emailAccount, languageId, tokens, toEmail, toName));
        }
        /// <summary>
        /// Sends 'New customer' notification message to a store owner
        /// </summary>
        /// <param name="customer">Customer instance</param>
        /// <param name="languageId">Message language identifier</param>
        /// <returns>Queued email identifier</returns>
        public virtual int SendCustomerAppointmentNotificationMessage(Customer customer, int languageId, IList <Token> tokens)
        {
            if (customer == null)
            {
                throw new ArgumentNullException("customer");
            }

            var store = _storeContext.CurrentStore;

            var messageTemplate = _messageTemplateService.GetMessageTemplateByName("Appointment.New", store.Id);

            if (messageTemplate == null)
            {
                return(0);
            }

            //email account
            var emailAccount = GetEmailAccountOfMessageTemplate(messageTemplate, languageId);

            _messageTokenProvider.AddStoreTokens(tokens, store, emailAccount);
            _messageTokenProvider.AddCustomerTokens(tokens, customer);


            //event notification
            _eventPublisher.MessageTokensAdded(messageTemplate, tokens);

            var toEmail = emailAccount.Email;
            var toName  = emailAccount.DisplayName;

            return(_workflowMessageService.SendNotification(messageTemplate, emailAccount, languageId, tokens, toEmail, toName));
        }
Пример #3
0
        /// <summary>
        /// Sends a welcome message to a customer
        /// </summary>
        /// <param name="customer">Customer instance</param>
        /// <returns>Queued email identifier</returns>
        public int SendCustomerWelcomeMessage(Customer customer)
        {
            if (customer == null)
            {
                throw new ArgumentNullException("customer");
            }

            var messageTemplate = GetActiveMessageTemplate("Customer.WelcomeMessage");

            if (messageTemplate == null)
            {
                return(0);
            }

            //email account
            var emailAccount = GetEmailAccountOfMessageTemplate(messageTemplate);

            //tokens
            var tokens = new List <Token>();

            _messageTokenProvider.AddStoreTokens(tokens, emailAccount);
            _messageTokenProvider.AddCustomerTokens(tokens, customer);

            //event notification
            _eventPublisher.MessageTokensAdded(messageTemplate, tokens);

            var toEmail = customer.Email;
            var toName  = customer.UserName; //原来是获取全称

            return(SendNotification(messageTemplate, emailAccount,
                                    tokens,
                                    toEmail, toName));
        }
        public virtual IList <int> SendAdminEmail(string email, string subject, string body)
        {
            int languageId = _languageService.GetAllLanguages().Where(x => x.LanguageCulture == "en-US").FirstOrDefault().Id;
            var store      = _storeContext.CurrentStore;

            languageId = EnsureLanguageIsActive(languageId, store.Id);

            var messageTemplates = GetActiveMessageTemplates(MessageTemplateSystemNames.AdminMessage, store.Id);

            if (!messageTemplates.Any())
            {
                return(new List <int>());
            }

            //tokens
            var commonTokens = new List <Token>();

            commonTokens.Add(new Token("Admin.Body", body));

            return(messageTemplates.Select(messageTemplate =>
            {
                //email account
                var emailAccount = GetEmailAccountOfMessageTemplate(messageTemplate, languageId);

                var tokens = new List <Token>(commonTokens);
                _messageTokenProvider.AddStoreTokens(tokens, store, emailAccount);

                //event notification
                _eventPublisher.MessageTokensAdded(messageTemplate, tokens);

                return SendNotification(messageTemplate, emailAccount, languageId, tokens, email, "", "", "", "", "", "", "", subject);
            }).ToList());
        }
Пример #5
0
        /// <summary>
        /// Sends 'New user' notification message to a store owner
        /// </summary>
        /// <param name="user">User instance</param>
        /// <param name="languageId">Message language identifier</param>
        /// <returns>Queued email identifier</returns>
        public virtual IList <int> SendUserRegisteredNotificationMessage(User user, int languageId)
        {
            if (user == null)
            {
                throw new ArgumentNullException(nameof(user));
            }

            var messageTemplates = GetActiveMessageTemplates(MessageTemplateSystemNames.UserRegisteredNotification);

            if (!messageTemplates.Any())
            {
                return(new List <int>());
            }

            //tokens
            var commonTokens = new List <Token>();

            _messageTokenProvider.AddUserTokens(commonTokens, user);

            return(messageTemplates.Select(messageTemplate =>
            {
                //email account
                var emailAccount = GetEmailAccountOfMessageTemplate(messageTemplate, languageId);

                var tokens = new List <Token>(commonTokens);

                //event notification
                _eventPublisher.MessageTokensAdded(messageTemplate, tokens);

                var toEmail = emailAccount.Email;
                var toName = emailAccount.DisplayName;

                return SendNotification(messageTemplate, emailAccount, languageId, tokens, toEmail, toName);
            }).ToList());
        }
Пример #6
0
        public virtual int SendShareInfoMessage(Customer customer, int languageId, string customerEmail, string customerName, string friendsEmail, string personalMessage)
        {
            //Check customer
            if (customer == null)
            {
                throw new ArgumentNullException("customer");
            }

            //Get Store
            var store = _storeContext.CurrentStore;

            //Get language
            languageId = EnsureLanguageIsActive(languageId, store.Id);

            //Get Template
            var messageTemplate = GetActiveMessageTemplate("Cameleo.ShareInfo", store.Id);

            if (messageTemplate == null)
            {
                return(0);
            }

            //email account
            var emailAccount = GetEmailAccountOfMessageTemplate(messageTemplate, languageId);

            //tokens
            var tokens = new List <Token>();

            _messageTokenProvider.AddStoreTokens(tokens, store, emailAccount);
            _messageTokenProvider.AddCustomerTokens(tokens, customer);
            tokens.Add(new Token("EmailAFriend.FullName", customerName));
            tokens.Add(new Token("EmailAFriend.PersonalMessage", personalMessage, true));
            tokens.Add(new Token("EmailAFriend.Email", customerEmail));

            //event notification
            _eventPublisher.MessageTokensAdded(messageTemplate, tokens);

            //Send message
            var toEmail      = friendsEmail;
            var toName       = "";
            int newMessageId = SendShareInfoNotification(messageTemplate, emailAccount, languageId, tokens, toEmail, toName);

            return(newMessageId);
        }
Пример #7
0
        private int SetupEmail(ref EmailAccount account, ref MessageTemplate messageTemplate, ref List <Token> tokens, Customer customer)
        {
            var languageId = EnsureLanguageIsActive(0, _store.Id);

            account = GetEmailAccountOfMessageTemplate(messageTemplate, languageId);

            _messageTokenProvider.AddStoreTokens(tokens, _store, account);
            _messageTokenProvider.AddCustomerTokens(tokens, customer);

            _eventPublisher.MessageTokensAdded(messageTemplate, tokens);

            return(languageId);
        }
        /// <summary>
        /// Sends a test email
        /// </summary>
        /// <param name="messageTemplateId">Message template identifier</param>
        /// <param name="userIds">Send to email</param>
        /// <param name="tokens">Tokens</param>
        /// <param name="languageId">Message language identifier</param>
        /// <returns>Queued email identifier</returns>
        public virtual int SendTestNotification(int messageTemplateId, string userIds, List <Token> tokens, int languageId)
        {
            var messageTemplate = _messageTemplateService.GetMessageTemplateById(messageTemplateId);

            if (messageTemplate == null)
            {
                throw new ArgumentException("Template cannot be loaded");
            }

            //event notification
            _eventPublisher.MessageTokensAdded(messageTemplate, tokens);

            return(SendNotification(string.Empty, messageTemplate, languageId, tokens));
        }
Пример #9
0
        /// <summary>
        ///     Sends 'New customer' notification message to a store owner
        /// </summary>
        /// <param name="customer">Customer instance</param>
        /// <param name="languageId">Message language identifier</param>
        /// <returns>Queued email identifier</returns>
        public virtual int SendCustomerRegisteredNotificationMessage(Customer customer, int languageId)
        {
            if (customer == null)
            {
                throw new ArgumentNullException("customer");
            }

            languageId = EnsureLanguageIsActive(languageId);

            var messageTemplate = GetActiveMessageTemplate("NewCustomer.Notification");

            if (messageTemplate == null)
            {
                return(0);
            }

            //email account
            var emailAccount = GetEmailAccountOfMessageTemplate(messageTemplate, languageId);

            //tokens
            var tokens = new List <Token>();

            _messageTokenProvider.AddStoreTokens(tokens, EngineContext.Current.Resolve <StoreInformationSettings>(),
                                                 emailAccount);
            _messageTokenProvider.AddCustomerTokens(tokens, customer);

            //event notification
            _eventPublisher.MessageTokensAdded(messageTemplate, tokens);

            var toEmail = emailAccount.Email;
            var toName  = emailAccount.DisplayName;

            return(SendNotification(messageTemplate, emailAccount,
                                    languageId, tokens,
                                    toEmail, toName));
        }
Пример #10
0
        private bool SendFreeSampleMessage(HomeInstallationQuoteModel Model)
        {
            MessageTemplate messageTemplate =
                GetLocalizedActiveMessageTemplate("HomeInstallationQuote.Form");

            if (messageTemplate == null)
            {
                return(false);
            }

            EmailAccount sendTo = GetEmailAccountOfMessageTemplate(messageTemplate,
                                                                   _workContext.WorkingLanguage.Id);
            IList <Token> tokens = GenerateTokens(Model);

            _eventPublisher.MessageTokensAdded(messageTemplate, tokens);
            return(0 != SendMessage(messageTemplate, Model.Name, Model.Email, sendTo,
                                    _workContext.WorkingLanguage.Id, tokens));
        }
Пример #11
0
        /// <summary>
        /// Sends 'New user' notification message to a store owner
        /// </summary>
        /// <param name="user">User instance</param>
        /// <param name="languageId">Message language identifier</param>
        /// <returns>Queued email identifier</returns>
        public virtual int SendUserRegisteredNotificationMessage(User user, int languageId)
        {
            if (user == null)
            {
                throw new ArgumentNullException("user");
            }

            languageId = EnsureLanguageIsActive(languageId);

            var messageTemplate = GetLocalizedActiveMessageTemplate("NewUser.Notification", languageId);

            if (messageTemplate == null)
            {
                return(0);
            }

            //tokens
            var tokens = new List <Token>();

            _messageTokenProvider.AddSiteTokens(tokens);
            _messageTokenProvider.AddUserTokens(tokens, user);

            //event notification
            _eventPublisher.MessageTokensAdded(messageTemplate, tokens);

            var emailAccount = GetEmailAccountOfMessageTemplate(messageTemplate, languageId);
            var toEmail      = emailAccount.Email;
            var toName       = emailAccount.DisplayName;

            // use user email as reply address
            var replyTo = GetReplyToEmail(user);

            return(SendNotification(messageTemplate, emailAccount,
                                    languageId, tokens,
                                    toEmail, toName,
                                    replyTo.Item1, replyTo.Item2));
        }
        /// <summary>
        /// Method to send error notification to store owner
        /// </summary>
        /// <param name="order"></param>
        /// <param name="languageId"></param>
        /// <param name="nopShiprocketOrder"></param>
        /// <returns></returns>
        public virtual int SendOrderShiprocketErrorStoreOwnerNotification(Order order, int languageId, NopShiprocketOrder nopShiprocketOrder)
        {
            if (order == null)
            {
                throw new ArgumentNullException(nameof(order));
            }

            var store = _storeService.GetStoreById(order.StoreId) ?? _storeContext.CurrentStore;

            languageId = EnsureLanguageIsActive(languageId, store.Id);

            var messageTemplates = GetActiveMessageTemplates(MessageTemplateSystemNames.OrderPlacedStoreOwnerNotification, store.Id);

            if (!messageTemplates.Any())
            {
                return(0);
            }

            //email account
            var emailAccount = GetEmailAccountOfMessageTemplate(messageTemplates.FirstOrDefault(), languageId);

            //tokens
            var tokens = new List <Token>();

            _messageTokenProvider.AddStoreTokens(tokens, store, emailAccount);
            _messageTokenProvider.AddOrderTokens(tokens, order, languageId);
            _messageTokenProvider.AddCustomerTokens(tokens, _customerService.GetCustomerById(order.CustomerId));

            //event notification
            _eventPublisher.MessageTokensAdded(messageTemplates.FirstOrDefault(), tokens);

            var toEmail = emailAccount.Email;
            var toName  = emailAccount.DisplayName;

            return(SendErrorNotification(messageTemplates.FirstOrDefault(), emailAccount, languageId, tokens, toEmail, toName, null, null, null, null, null, null, null, nopShiprocketOrder));
        }
Пример #13
0
        /// <summary>
        /// Executes a task
        /// </summary>
        public string Execute([FromQuery(Name = "roles")] int[] roles)
        {
            var store = _storeContext.CurrentStore;
            //load language by specified ID
            var languageId = 1;

            //var messageTemplate = _messageTemplateService.GetMessageTemplateByName(MessageTemplateSystemNames.CustomerForceChangePasswordMessage, 0);
            var messageTemplate = _messageTemplateService.GetMessageTemplateById(44);

            //no template found
            if (messageTemplate == null)
            {
                return("messageTemplate is null");
            }

            //ensure it's active
            var isActive = messageTemplate.IsActive;

            if (!isActive)
            {
                return("messageTemplate is not active");
            }


            var emailAccountId = messageTemplate.GetLocalized(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 emailAccount = _emailAccountService.GetEmailAccountById(emailAccountId);

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


            //tokens
            var tokens = new List <Token>();

            _messageTokenProvider.AddStoreTokens(tokens, store, emailAccount);

            //var customers = _customerService.GetAllCustomers(customerRoleIds: new int[] { 1, 2, 3 });
            var customers = _customerService.GetAllCustomers(customerRoleIds: roles);

            foreach (var customer in customers)
            {
                _messageTokenProvider.AddCustomerTokens(tokens, customer);

                //event notification
                _eventPublisher.MessageTokensAdded(messageTemplate, tokens);

                var toEmail = customer.Email;
                var toName  = customer.GetFullName();


                if (string.IsNullOrEmpty(toEmail))
                {
                    continue;
                }

                //return SendNotification(messageTemplate, emailAccount, languageId, tokens, toEmail, toName);
                if (messageTemplate == null)
                {
                    throw new ArgumentNullException(nameof(messageTemplate));
                }

                if (emailAccount == null)
                {
                    throw new ArgumentNullException(nameof(emailAccount));
                }

                //retrieve localized message template data
                var bcc = messageTemplate.GetLocalized(mt => mt.BccEmailAddresses, languageId);

                var subject = messageTemplate.GetLocalized(mt => mt.Subject, languageId);
                var body    = messageTemplate.GetLocalized(mt => mt.Body, languageId);

                //Replace subject and body tokens
                var subjectReplaced = _tokenizer.Replace(subject, tokens, false);
                var bodyReplaced    = _tokenizer.Replace(body, tokens, true);

                //limit name length
                toName = CommonHelper.EnsureMaximumLength(toName, 300);

                var email = new QueuedEmail
                {
                    Priority = QueuedEmailPriority.High,
                    From     = emailAccount.Email,
                    FromName = emailAccount.DisplayName,
                    To       = toEmail,
                    ToName   = toName,
                    //ReplyTo = replyToEmailAddress,
                    //ReplyToName = replyToName,
                    CC      = string.Empty,
                    Bcc     = bcc,
                    Subject = subjectReplaced,
                    Body    = bodyReplaced,
                    //AttachmentFilePath = attachmentFilePath,
                    //AttachmentFileName = attachmentFileName,
                    AttachedDownloadId    = messageTemplate.AttachedDownloadId,
                    CreatedOnUtc          = DateTime.UtcNow,
                    EmailAccountId        = emailAccount.Id,
                    DontSendBeforeDateUtc = !messageTemplate.DelayBeforeSend.HasValue ? null
                        : (DateTime?)(DateTime.UtcNow + TimeSpan.FromHours(messageTemplate.DelayPeriod.ToHours(messageTemplate.DelayBeforeSend.Value)))
                };

                _queuedEmailService.InsertQueuedEmail(email);
            }


            return("Mass change Password email process completed");
            //var olderThanMinutes = _customerSettings.DeleteGuestTaskOlderThanMinutes;
            //// Default value in case 0 is returned.  0 would effectively disable this service and harm performance.
            //olderThanMinutes = olderThanMinutes == 0 ? 1440 : olderThanMinutes;

            //_customerService.DeleteGuestCustomers(null, DateTime.UtcNow.AddMinutes(-olderThanMinutes), true);
        }
Пример #14
0
        public int SendFriendRequestNotification(User customer, int friendRequestCount, int languageId, int storeId)
        {
            var store = _storeService.GetStoreById(storeId);

            languageId = EnsureLanguageIsActive(languageId, store.Id);


            var messageTemplate = GetLocalizedActiveMessageTemplate("MobSocial.FriendRequestNotification", store.Id);

            if (messageTemplate == null)
            {
                return(0);
            }


            var emailAccount = GetEmailAccountOfMessageTemplate(messageTemplate, languageId);

            //tokens
            var tokens = new List <Token>();

            _messageTokenProvider.AddStoreTokens(tokens, store, emailAccount);
            _messageTokenProvider.AddUserTokens(tokens, customer);
            tokens.Add(new Token("FriendRequestCount", friendRequestCount.ToString()));


            //event notification
            _eventPublisher.MessageTokensAdded(messageTemplate, tokens);


            var toEmail = customer.Email;
            var toName  = customer.GetFullName().ToTitleCase();


            return(SendNotification(messageTemplate, emailAccount, languageId, tokens, toEmail, toName));
        }
Пример #15
0
        /// <summary>
        /// Sends 'New customer' notification message to a store owner
        /// </summary>
        /// <param name="customer">Customer instance</param>
        /// <param name="languageId">Message language identifier</param>
        /// <returns>Queued email identifier</returns>
        public virtual IList <int> SendCustomerRegisteredNotificationMessage(Customer customer, int languageId)
        {
            if (customer == null)
            {
                throw new ArgumentNullException(nameof(customer));
            }

            var store = _storeContext.CurrentStore;

            languageId = EnsureLanguageIsActive(languageId, store.Id);

            var messageTemplates = GetActiveMessageTemplates(MessageTemplateSystemNames.CustomerRegisteredNotification, store.Id);

            if (!messageTemplates.Any())
            {
                return(new List <int>());
            }

            //tokens
            var commonTokens = new List <Token>();

            _messageTokenProvider.AddCustomerTokens(commonTokens, customer);

            return(messageTemplates.Select(messageTemplate =>
            {
                //email account
                var emailAccount = GetEmailAccountOfMessageTemplate(messageTemplate, languageId);

                var tokens = new List <Token>(commonTokens);
                _messageTokenProvider.AddStoreTokens(tokens, store, emailAccount);

                //event notification
                _eventPublisher.MessageTokensAdded(messageTemplate, tokens);

                var toEmail = emailAccount.Email;
                var toName = emailAccount.DisplayName;

                return SendNotification(messageTemplate, emailAccount, languageId, tokens, toEmail, toName);
            }).ToList());
        }