Ejemplo n.º 1
0
        /// <summary>
        /// Sends feedback for a particular submission.
        /// </summary>
        private async Task <Tuple <Submission, bool> > SendSubmissionFeedbackAsync(
            Submission submission,
            Func <Submission, string> markReadUrlBuilder)
        {
            var user = submission.Commit.User;

            try
            {
                await _emailProvider.SendMessageAsync
                (
                    new List <EmailRecipient>() { new EmailRecipient($"{user.FirstName} {user.LastName}", user.EmailAddress) },
                    $"{submission.Checkpoint.Project.Name} {submission.Checkpoint.DisplayName} Feedback",
                    $"{submission.Feedback.Replace("\n", "<br>")}<br><br><a href=\"{markReadUrlBuilder(submission)}\">Click here</a> to mark this feedback as read.",
                    broadcast : false
                );

                return(new Tuple <Submission, bool>(submission, true));
            }
            catch (Exception ex)
            {
                _logger.LogError
                (
                    0,
                    ex,
                    "Failed to send e-mail to {emailAddress}",
                    submission.Commit.User.EmailAddress
                );

                return(new Tuple <Submission, bool>(submission, false));
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Sends an e-mail to the student and the admins of the class
 /// that are section recipients for the student's section.
 /// </summary>
 private async Task SendEmailAsync(
     Message message,
     string conversationUrl,
     Func <int, string> getAttachmentUrl,
     Func <DateTime, string> formatDateTime)
 {
     await _emailProvider.SendMessageAsync
     (
         await GetEmailRecipientsAsync(message),
         GetEmailSubject(message),
         GetEmailContents(message, conversationUrl, getAttachmentUrl, formatDateTime),
         GetEmailSender(message),
         GetEmailThreadInfo(message)
     );
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Sends an e-mail to the student and the admins of the class
        /// that are section recipients for the student's section.
        /// </summary>
        private async Task SendEmailAsync(
            Message message,
            string conversationUrl,
            Func <int, string> getAttachmentUrl,
            Func <DateTime, string> formatDateTime)
        {
            var(recipients, subject) = await GetEnvelopeAsync(message);

            var attachments = GetEmailAttachmentList(message, getAttachmentUrl);
            var footer      = GetEmailFooter(message, formatDateTime, conversationUrl);

            await _emailProvider.SendMessageAsync
            (
                recipients,
                subject,
                message.Contents + _htmlSanitizer.SanitizeHtml(attachments + footer)
            );
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Sends the user an invitation mail.
        /// </summary>
        private async Task SendUserInvitationMailAsync(User user, string confirmUrlBuilder)
        {
            var confirmUrl = confirmUrlBuilder.Replace("REPLACE", user.EmailConfirmationCode);

            await _emailProvider.SendMessageAsync
            (
                new List <EmailRecipient>()
            {
                new EmailRecipient
                (
                    $"{user.FirstName} {user.LastName}",
                    user.EmailAddress
                )
            },
                "Confirm your e-mail address with CS Classroom",
                $"Hi {user.FirstName},<br><br>Thank you for registering for CS Classroom. Please <a href=\"{confirmUrl}\">click here</a> to confirm your e-mail address."
            );
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Sends an e-mail with the announcement to all students in the section,
        /// and all admins of the classroom.
        /// </summary>
        private async Task SendAnnouncementEmailAsync(
            Announcement announcement,
            Classroom classroom,
            IList <int> sectionIds,
            Func <DateTime, string> formatDateTime,
            bool emailAdmins)
        {
            var students = await _dbContext.SectionMemberships
                           .Where(sm => sm.ClassroomMembership.ClassroomId == classroom.Id)
                           .Where(sm => sm.Role == SectionRole.Student)
                           .Where(sm => sectionIds.Contains(sm.SectionId))
                           .Include(sm => sm.ClassroomMembership.User)
                           .Include(sm => sm.ClassroomMembership.User.AdditionalContacts)
                           .ToListAsync();

            var users = students.Select(sm => sm.ClassroomMembership.User).ToList();

            if (emailAdmins)
            {
                var adminRecipients = await _dbContext.SectionRecipients
                                      .Where(sr => sr.ClassroomMembership.ClassroomId == classroom.Id)
                                      .Where(sr => sr.EmailAnnouncements)
                                      .Include(sr => sr.ClassroomMembership.User.AdditionalContacts)
                                      .ToListAsync();

                users.AddRange
                (
                    adminRecipients
                    .Where(ar => sectionIds.Contains(ar.SectionId))
                    .Select(ar => ar.ClassroomMembership.User)
                    .Distinct()
                );
            }

            if (users.Any())
            {
                if (announcement.User == null)
                {
                    await _dbContext.Entry(announcement).Reference(a => a.User).LoadAsync();
                }

                var recipients = new List <EmailRecipient>();
                foreach (var user in users.Distinct())
                {
                    recipients.Add
                    (
                        new EmailRecipient
                        (
                            $"{user.FirstName} {user.LastName}",
                            user.EmailAddress
                        )
                    );

                    if (user.AdditionalContacts != null)
                    {
                        foreach (var additionalContact in user.AdditionalContacts)
                        {
                            recipients.Add
                            (
                                new EmailRecipient
                                (
                                    $"{additionalContact.FirstName} {additionalContact.LastName}",
                                    additionalContact.EmailAddress
                                )
                            );
                        }
                    }
                }

                await _emailProvider.SendMessageAsync
                (
                    recipients,
                    $"{classroom.DisplayName}: {announcement.Title}",
                    announcement.Contents + GetEmailFooter(announcement, formatDateTime)
                );
            }
        }
Ejemplo n.º 6
0
 public async Task SendMessageAsync(string email, string callBack)
 {
     await emailProvider.SendMessageAsync(
         new VerificationMessage(email, SendVerificationLinkHelper.Title, SendVerificationLinkHelper.Subject),
         new VerificationMessageContext(callBack));
 }