Search in sources :

Example 21 with EmailWrapper

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");
}
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 22 with EmailWrapper

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;
}
Also used : EmailWrapper(teammates.common.util.EmailWrapper)

Example 23 with EmailWrapper

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());
}
Also used : InternetAddress(javax.mail.internet.InternetAddress) MimeMessage(javax.mail.internet.MimeMessage) JavamailService(teammates.logic.core.JavamailService) EmailWrapper(teammates.common.util.EmailWrapper) Test(org.testng.annotations.Test)

Example 24 with EmailWrapper

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());
    }
}
Also used : MailgunService(teammates.logic.core.MailgunService) FormDataMultiPart(com.sun.jersey.multipart.FormDataMultiPart) EmailWrapper(teammates.common.util.EmailWrapper) Test(org.testng.annotations.Test)

Example 25 with EmailWrapper

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

Aggregations

EmailWrapper (teammates.common.util.EmailWrapper)55 EmailGenerator (teammates.logic.api.EmailGenerator)24 Test (org.testng.annotations.Test)20 CourseAttributes (teammates.common.datatransfer.attributes.CourseAttributes)15 InstructorAttributes (teammates.common.datatransfer.attributes.InstructorAttributes)15 StudentAttributes (teammates.common.datatransfer.attributes.StudentAttributes)13 TeammatesException (teammates.common.exception.TeammatesException)13 FeedbackSessionAttributes (teammates.common.datatransfer.attributes.FeedbackSessionAttributes)12 ArrayList (java.util.ArrayList)6 AccountAttributes (teammates.common.datatransfer.attributes.AccountAttributes)4 FeedbackQuestionAttributes (teammates.common.datatransfer.attributes.FeedbackQuestionAttributes)3 FeedbackResponseAttributes (teammates.common.datatransfer.attributes.FeedbackResponseAttributes)3 EmailSendingException (teammates.common.exception.EmailSendingException)3 NullPostParameterException (teammates.common.exception.NullPostParameterException)3 StatusMessage (teammates.common.util.StatusMessage)3 RedirectResult (teammates.ui.controller.RedirectResult)3 Instant (java.time.Instant)2 DataBundle (teammates.common.datatransfer.DataBundle)2 FeedbackNumericalScaleQuestionDetails (teammates.common.datatransfer.questions.FeedbackNumericalScaleQuestionDetails)2 EntityDoesNotExistException (teammates.common.exception.EntityDoesNotExistException)2