Search in sources :

Example 6 with EmailGenerator

use of teammates.logic.api.EmailGenerator in project teammates by TEAMMATES.

the class EmailGeneratorTest method testGenerateCompiledLogsEmail.

@Test
public void testGenerateCompiledLogsEmail() throws IOException {
    AppLogLine typicalLogLine = new AppLogLine();
    typicalLogLine.setLogLevel(LogLevel.ERROR);
    typicalLogLine.setLogMessage("Typical log message");
    AppLogLine logLineWithLineBreak = new AppLogLine();
    logLineWithLineBreak.setLogLevel(LogLevel.ERROR);
    logLineWithLineBreak.setLogMessage("Log line \n with line break <br> and also HTML br tag");
    EmailWrapper email = new EmailGenerator().generateCompiledLogsEmail(Arrays.asList(typicalLogLine, logLineWithLineBreak));
    String subject = String.format(EmailType.SEVERE_LOGS_COMPILATION.getSubject(), Config.getAppVersion());
    verifyEmail(email, Config.SUPPORT_EMAIL, subject, "/severeLogsCompilationEmail.html");
}
Also used : EmailGenerator(teammates.logic.api.EmailGenerator) AppLogLine(com.google.appengine.api.log.AppLogLine) EmailWrapper(teammates.common.util.EmailWrapper) Test(org.testng.annotations.Test)

Example 7 with EmailGenerator

use of teammates.logic.api.EmailGenerator in project teammates by TEAMMATES.

the class EmailGeneratorTest method testGenerateInstructorJoinEmail.

@Test
public void testGenerateInstructorJoinEmail() throws IOException {
    ______TS("instructor new account email");
    String instructorEmail = "instructor@email.tmt";
    String instructorName = "Instr";
    String regkey = "skxxxxxxxxxks";
    @SuppressWarnings("deprecation") InstructorAttributes instructor = InstructorAttributes.builder("googleId", "courseId", "Instructor Name", instructorEmail).withKey(regkey).build();
    AccountAttributes inviter = AccountAttributes.builder().withEmail("instructor-joe@gmail.com").withName("Joe Wilson").build();
    String joinLink = Config.getAppUrl(Const.ActionURIs.INSTRUCTOR_COURSE_JOIN).withRegistrationKey(StringHelper.encrypt(regkey)).withInstructorInstitution("Test Institute").toAbsoluteString();
    EmailWrapper email = new EmailGenerator().generateNewInstructorAccountJoinEmail(instructorEmail, instructorName, joinLink);
    String subject = String.format(EmailType.NEW_INSTRUCTOR_ACCOUNT.getSubject(), instructorName);
    verifyEmail(email, instructorEmail, subject, "/instructorNewAccountEmail.html");
    assertEquals(email.getBcc(), Config.SUPPORT_EMAIL);
    ______TS("instructor course join email");
    CourseAttributes course = CourseAttributes.builder("course-id", "Course Name", ZoneId.of("UTC")).build();
    email = new EmailGenerator().generateInstructorCourseJoinEmail(inviter, instructor, course);
    subject = String.format(EmailType.INSTRUCTOR_COURSE_JOIN.getSubject(), course.getName(), course.getId());
    verifyEmail(email, instructor.email, subject, "/instructorCourseJoinEmail.html");
}
Also used : EmailGenerator(teammates.logic.api.EmailGenerator) AccountAttributes(teammates.common.datatransfer.attributes.AccountAttributes) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) EmailWrapper(teammates.common.util.EmailWrapper) CourseAttributes(teammates.common.datatransfer.attributes.CourseAttributes) Test(org.testng.annotations.Test)

Example 8 with EmailGenerator

use of teammates.logic.api.EmailGenerator in project teammates by TEAMMATES.

the class StudentCourseJoinEmailWorkerAction method execute.

@Override
public void execute() {
    String courseId = getRequestParamValue(ParamsNames.COURSE_ID);
    Assumption.assertPostParamNotNull(ParamsNames.COURSE_ID, courseId);
    String studentEmail = getRequestParamValue(ParamsNames.STUDENT_EMAIL);
    Assumption.assertPostParamNotNull(ParamsNames.STUDENT_EMAIL, studentEmail);
    String isRejoinString = getRequestParamValue(ParamsNames.IS_STUDENT_REJOINING);
    Assumption.assertPostParamNotNull(ParamsNames.IS_STUDENT_REJOINING, isRejoinString);
    boolean isRejoin = Boolean.parseBoolean(isRejoinString);
    CourseAttributes course = logic.getCourse(courseId);
    Assumption.assertNotNull(course);
    StudentAttributes student = logic.getStudentForEmail(courseId, studentEmail);
    Assumption.assertNotNull(student);
    EmailWrapper email = isRejoin ? new EmailGenerator().generateStudentCourseRejoinEmailAfterGoogleIdReset(course, student) : new EmailGenerator().generateStudentCourseJoinEmail(course, student);
    try {
        emailSender.sendEmail(email);
    } catch (Exception e) {
        Assumption.fail("Unexpected error while sending email" + TeammatesException.toStringWithStackTrace(e));
    }
}
Also used : EmailGenerator(teammates.logic.api.EmailGenerator) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) TeammatesException(teammates.common.exception.TeammatesException) CourseAttributes(teammates.common.datatransfer.attributes.CourseAttributes) EmailWrapper(teammates.common.util.EmailWrapper)

Example 9 with EmailGenerator

use of teammates.logic.api.EmailGenerator in project teammates by TEAMMATES.

the class AdminSendEmailWorkerAction method execute.

@Override
public void execute() {
    String receiverEmail = getRequestParamValue(ParamsNames.ADMIN_EMAIL_RECEIVER);
    Assumption.assertPostParamNotNull(ParamsNames.ADMIN_EMAIL_RECEIVER, receiverEmail);
    String emailContent = getRequestParamValue(ParamsNames.ADMIN_EMAIL_CONTENT);
    String emailSubject = getRequestParamValue(ParamsNames.ADMIN_EMAIL_SUBJECT);
    if (emailContent == null || emailSubject == null) {
        String emailId = getRequestParamValue(ParamsNames.ADMIN_EMAIL_ID);
        Assumption.assertPostParamNotNull(ParamsNames.ADMIN_EMAIL_ID, emailId);
        log.info("Sending large email. Going to retrieve email content and subject from datastore.");
        AdminEmailAttributes adminEmail = logic.getAdminEmailById(emailId);
        Assumption.assertNotNull(adminEmail);
        emailContent = adminEmail.getContentValue();
        emailSubject = adminEmail.getSubject();
    }
    Assumption.assertNotNull(emailContent);
    Assumption.assertNotNull(emailSubject);
    try {
        EmailWrapper email = new EmailGenerator().generateAdminEmail(emailContent, emailSubject, receiverEmail);
        emailSender.sendEmail(email);
        log.info("Email sent to " + receiverEmail);
    } catch (Exception e) {
        log.severe("Unexpected error while sending admin emails: " + TeammatesException.toStringWithStackTrace(e));
    }
}
Also used : EmailGenerator(teammates.logic.api.EmailGenerator) TeammatesException(teammates.common.exception.TeammatesException) AdminEmailAttributes(teammates.common.datatransfer.attributes.AdminEmailAttributes) EmailWrapper(teammates.common.util.EmailWrapper)

Example 10 with EmailGenerator

use of teammates.logic.api.EmailGenerator in project teammates by TEAMMATES.

the class CompileLogsAction method sendEmail.

private void sendEmail(List<AppLogLine> logs) {
    // Do not send any emails if there are no severe logs; prevents spamming
    if (!logs.isEmpty()) {
        EmailWrapper message = new EmailGenerator().generateCompiledLogsEmail(logs);
        emailSender.sendReport(message);
    }
}
Also used : EmailGenerator(teammates.logic.api.EmailGenerator) EmailWrapper(teammates.common.util.EmailWrapper)

Aggregations

EmailWrapper (teammates.common.util.EmailWrapper)24 EmailGenerator (teammates.logic.api.EmailGenerator)24 TeammatesException (teammates.common.exception.TeammatesException)12 CourseAttributes (teammates.common.datatransfer.attributes.CourseAttributes)10 FeedbackSessionAttributes (teammates.common.datatransfer.attributes.FeedbackSessionAttributes)10 InstructorAttributes (teammates.common.datatransfer.attributes.InstructorAttributes)10 Test (org.testng.annotations.Test)9 StudentAttributes (teammates.common.datatransfer.attributes.StudentAttributes)9 ArrayList (java.util.ArrayList)3 AccountAttributes (teammates.common.datatransfer.attributes.AccountAttributes)3 EmailSendingException (teammates.common.exception.EmailSendingException)3 StatusMessage (teammates.common.util.StatusMessage)3 Instant (java.time.Instant)2 EntityDoesNotExistException (teammates.common.exception.EntityDoesNotExistException)2 InvalidParametersException (teammates.common.exception.InvalidParametersException)2 AppLogLine (com.google.appengine.api.log.AppLogLine)1 AdminEmailAttributes (teammates.common.datatransfer.attributes.AdminEmailAttributes)1 FeedbackQuestionAttributes (teammates.common.datatransfer.attributes.FeedbackQuestionAttributes)1 FeedbackResponseAttributes (teammates.common.datatransfer.attributes.FeedbackResponseAttributes)1 FeedbackQuestionDetails (teammates.common.datatransfer.questions.FeedbackQuestionDetails)1