Example #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));
        }