use of teammates.common.util.EmailWrapper 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.common.util.EmailWrapper in project teammates by TEAMMATES.
the class EmailSenderTest method getTypicalEmailWrapper.
private EmailWrapper getTypicalEmailWrapper() {
String senderName = "Sender Name";
String senderEmail = "sender@email.com";
String replyTo = "replyto@email.com";
String recipient = "recipient@email.com";
String bcc = "bcc@email.com";
String subject = "Test subject";
String content = "<p>This is a test content</p>";
EmailWrapper wrapper = new EmailWrapper();
wrapper.setSenderName(senderName);
wrapper.setSenderEmail(senderEmail);
wrapper.setReplyTo(replyTo);
wrapper.setRecipient(recipient);
wrapper.setBcc(bcc);
wrapper.setSubject(subject);
wrapper.setContent(content);
return wrapper;
}
use of teammates.common.util.EmailWrapper in project teammates by TEAMMATES.
the class EmailSenderTest method testConvertToMimeMessage.
@Test
public void testConvertToMimeMessage() throws Exception {
EmailWrapper wrapper = getTypicalEmailWrapper();
MimeMessage email = new JavamailService().parseToEmail(wrapper);
assertEquals(new InternetAddress(wrapper.getSenderEmail(), wrapper.getSenderName()), email.getFrom()[0]);
assertEquals(new InternetAddress(wrapper.getReplyTo()), email.getReplyTo()[0]);
assertEquals(new InternetAddress(wrapper.getRecipient()), email.getRecipients(Message.RecipientType.TO)[0]);
assertEquals(new InternetAddress(wrapper.getBcc()), email.getRecipients(Message.RecipientType.BCC)[0]);
assertEquals(wrapper.getSubject(), email.getSubject());
assertEquals(wrapper.getContent(), email.getContent().toString());
}
use of teammates.common.util.EmailWrapper in project teammates by TEAMMATES.
the class EmailSenderTest method testConvertToMailgun.
@Test
public void testConvertToMailgun() throws Exception {
EmailWrapper wrapper = getTypicalEmailWrapper();
try (FormDataMultiPart formData = new MailgunService().parseToEmail(wrapper)) {
assertEquals(wrapper.getSenderName() + " <" + wrapper.getSenderEmail() + ">", formData.getField("from").getValue());
assertEquals(wrapper.getRecipient(), formData.getField("to").getValue());
assertEquals(wrapper.getBcc(), formData.getField("bcc").getValue());
assertEquals(wrapper.getReplyTo(), formData.getField("h:Reply-To").getValue());
assertEquals(wrapper.getSubject(), formData.getField("subject").getValue());
assertEquals(wrapper.getContent(), formData.getField("html").getValue());
}
}
use of teammates.common.util.EmailWrapper 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));
}
}
Aggregations