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");
}
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");
}
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));
}
}
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));
}
}
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);
}
}
Aggregations