コード例 #1
0
ファイル: UserManager.cs プロジェクト: ChuckLafferty/bugnet
        /// <summary>
        /// Sends the forgot password email.
        /// </summary>
        /// <param name="user">The user.</param>
        /// <param name="token">The token.</param>
        /// <exception cref="System.ArgumentNullException">
        /// user
        /// or
        /// user
        /// </exception>
        public static void SendForgotPasswordEmail(MembershipUser user, string token)
        {
            if (user == null) throw new ArgumentNullException("user");
            if (user.ProviderUserKey == null) throw new ArgumentNullException("user");

            IMailDeliveryService mailService = new SmtpMailDeliveryService();

            var emailFormatType = HostSettingManager.Get(HostSettingNames.SMTPEMailFormat, EmailFormatType.Text);
            var emailFormatKey = (emailFormatType == EmailFormatType.Text) ? "" : "HTML";
            const string subjectKey = "ForgotPasswordSubject";
            var bodyKey = string.Concat("ForgotPassword", emailFormatKey);
            var profile = new WebProfile().GetProfile(user.UserName);

            var nc = new CultureNotificationContent().LoadContent(profile.PreferredLocale, subjectKey, bodyKey);

            var notificationUser = new NotificationUser
            {
                Id = (Guid)user.ProviderUserKey,
                CreationDate = user.CreationDate,
                Email = user.Email,
                UserName = user.UserName,
                DisplayName = profile.DisplayName,
                FirstName = profile.FirstName,
                LastName = profile.LastName,
                IsApproved = user.IsApproved
            };

            var data = new Dictionary<string, object>
                {
                    {"Token", token}
                };

            var emailSubject = nc.CultureContents
                .First(p => p.ContentKey == subjectKey)
                .FormatContent();

            var bodyContent = nc.CultureContents
                .First(p => p.ContentKey == bodyKey)
                .TransformContent(data);

            var message = new MailMessage
            {
                Subject = emailSubject,
                Body = bodyContent,
                IsBodyHtml = true
            };

            mailService.Send(user.Email, message, null);
        }
コード例 #2
0
ファイル: UserManager.cs プロジェクト: ChuckLafferty/bugnet
        /// <summary>
        /// Sends the user registered notification.
        /// </summary>
        /// <param name="userName">The user.</param>
        public static void SendUserRegisteredNotification(string userName)
        {
            if (userName == "") throw new ArgumentNullException("userName");

            var user = GetUser(userName);
            if (user.ProviderUserKey == null) throw new ArgumentNullException("userName");

            // TODO - create this via dependency injection at some point.
            IMailDeliveryService mailService = new SmtpMailDeliveryService();

            var emailFormatType = HostSettingManager.Get(HostSettingNames.SMTPEMailFormat, EmailFormatType.Text);
            var emailFormatKey = (emailFormatType == EmailFormatType.Text) ? "" : "HTML";
            const string subjectKey = "UserRegisteredSubject";
            var bodyKey = string.Concat("UserRegistered", emailFormatKey);
            var profile = new WebProfile().GetProfile(user.UserName);

            var nc = new CultureNotificationContent().LoadContent(profile.PreferredLocale, subjectKey, bodyKey);

            var notificationUser = new NotificationUser
            {
                Id = (Guid)user.ProviderUserKey,
                CreationDate = user.CreationDate,
                Email = user.Email,
                UserName = user.UserName,
                DisplayName = profile.DisplayName,
                FirstName = profile.FirstName,
                LastName = profile.LastName,
                IsApproved = user.IsApproved
            };

            var data = new Dictionary<string, object> { { "User", notificationUser } };

            var emailSubject = nc.CultureContents
                .First(p => p.ContentKey == subjectKey)
                .FormatContent();

            var bodyContent = nc.CultureContents
                .First(p => p.ContentKey == bodyKey)
                .TransformContent(data);

            var message = new MailMessage
            {
                Subject = emailSubject,
                Body = bodyContent,
                IsBodyHtml = true
            };

            mailService.Send(user.Email, message, null);
        }