Exemple #1
0
        /// <summary>
        /// Send an email for validation
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="name"></param>
        /// <param name="mail"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        private async Task <Boolean> SendValidationMail(Int32 userId, String name, String mail, Guid token)
        {
            // Save
            String url = String.Format(
                "{0}/Account/ValidateMail/{1}?token={2}",
                Settings.Current.Url,
                userId.ToString(),
                token.ToString());

            String content = String.Format(Resources.EmailValidationContentFormat,
                                           name,
                                           Settings.Current.Url,
                                           url);

            // Send mail
            return(await MailService.Send(
                       mail,
                       name,
                       Resources.EmailValidationSubject,
                       content
                       ));
        }
Exemple #2
0
        /// <summary>
        /// Send mail onh comments subsribers when a comment has been added
        /// </summary>
        /// <param name="postId"></param>
        /// <param name="authorOfComment"></param>
        /// <returns></returns>
        private async Task NotifyUserForComment(Int32 postId, Int32 authorOfComment)
        {
            String authorMail = Settings.Current.AuthorMail;
            String authorName = Settings.Current.AuthorName;

            // Get post informations
            var post = (from p in _context.Posts
                        where p.Id == postId
                        select new
            {
                p.Title,
                // Take only other users with mail validated
                Users = (from u in p.CommentsFollowers
                         where u.Id != authorOfComment && u.EmailValidate && !String.IsNullOrEmpty(u.Email) && u.Email != authorMail
                         group u by u.Email into g
                         let c = g.FirstOrDefault()
                                 select new { c.Name, c.Email })
            }
                        ).FirstOrDefault();

            // data null
            if (post == null)
            {
                return;
            }

            Boolean result = true;

            // Format the mail subject
            String subject = String.Format(Resources.EMailCommentAddedSubject, post.Title);
            String postUri = GetPostUrl(postId, post.Title);

            if (post.Users?.Any() ?? false)
            {
                // Send mails
                foreach (var user in post.Users)
                {
                    result &= await MailService.Send(
                        user.Email,
                        user.Name,
                        subject,
                        String.Format(Resources.EMailCommentAddedContent,
                                      user.Name,
                                      postUri,
                                      post.Title)
                        );
                }
            }
            // Send mail to the author
            result &= await MailService.Send(
                authorMail,
                authorName,
                subject,
                String.Format(Resources.EMailCommentAddedContent,
                              authorName,
                              postUri,
                              post.Title)
                );

            if (!result)
            {
                Trace.TraceError("Erros when sennding comment notification on post " + postId);
            }
        }