Search in sources :

Example 1 with EmailException

use of org.pmiops.workbench.exceptions.EmailException in project workbench by all-of-us.

the class ProfileController method requestInvitationKey.

@Override
public ResponseEntity<Void> requestInvitationKey(String email) {
    Properties props = new Properties();
    Session session = Session.getDefaultInstance(props, null);
    try {
        Message msg = new MimeMessage(session);
        msg.setFrom(new InternetAddress("all-of-us-workbench-eng@googlegroups.com"));
        InternetAddress[] replyTo = new InternetAddress[1];
        replyTo[0] = new InternetAddress(email);
        msg.setReplyTo(replyTo);
        // To test the bug reporting functionality, change the recipient email to your email rather
        // than the group.
        // https://precisionmedicineinitiative.atlassian.net/browse/RW-40
        msg.addRecipient(Message.RecipientType.TO, new InternetAddress("all-of-us-workbench-eng@googlegroups.com", "AofU Workbench Engineers"));
        msg.setSubject("[AofU Invitation Key Request]");
        msg.setText(email + " is requesting the invitation key.");
        Transport.send(msg);
    } catch (MessagingException | UnsupportedEncodingException e) {
        throw new EmailException("Error sending invitation key request", e);
    }
    return ResponseEntity.status(HttpStatus.NO_CONTENT).build();
}
Also used : InternetAddress(javax.mail.internet.InternetAddress) Message(javax.mail.Message) MimeMessage(javax.mail.internet.MimeMessage) MimeMessage(javax.mail.internet.MimeMessage) MessagingException(javax.mail.MessagingException) EmailException(org.pmiops.workbench.exceptions.EmailException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Properties(java.util.Properties) Session(javax.mail.Session)

Example 2 with EmailException

use of org.pmiops.workbench.exceptions.EmailException in project workbench by all-of-us.

the class BugReportController method sendBugReport.

@Override
public ResponseEntity<BugReport> sendBugReport(BugReport bugReport) {
    Properties props = new Properties();
    Session session = Session.getDefaultInstance(props, null);
    try {
        Message msg = new MimeMessage(session);
        msg.setFrom(new InternetAddress("all-of-us-workbench-eng@googlegroups.com"));
        InternetAddress[] replyTo = new InternetAddress[1];
        replyTo[0] = new InternetAddress(bugReport.getContactEmail());
        msg.setReplyTo(replyTo);
        // To test the bug reporting functionality, change the recipient email to your email rather
        // than the group.
        // https://precisionmedicineinitiative.atlassian.net/browse/RW-40
        msg.addRecipient(Message.RecipientType.TO, new InternetAddress("all-of-us-workbench-eng@googlegroups.com", "AofU Workbench Engineers"));
        msg.setSubject("[AofU Bug Report]: " + bugReport.getShortDescription());
        msg.setText(bugReport.getReproSteps());
        Transport.send(msg);
    } catch (MessagingException e) {
        throw new EmailException("Error sending bug report", e);
    } catch (UnsupportedEncodingException e) {
        throw new EmailException("Error sending bug report", e);
    }
    return ResponseEntity.ok(bugReport);
}
Also used : InternetAddress(javax.mail.internet.InternetAddress) Message(javax.mail.Message) MimeMessage(javax.mail.internet.MimeMessage) MimeMessage(javax.mail.internet.MimeMessage) MessagingException(javax.mail.MessagingException) EmailException(org.pmiops.workbench.exceptions.EmailException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Properties(java.util.Properties) Session(javax.mail.Session)

Aggregations

UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 Properties (java.util.Properties)2 Message (javax.mail.Message)2 MessagingException (javax.mail.MessagingException)2 Session (javax.mail.Session)2 InternetAddress (javax.mail.internet.InternetAddress)2 MimeMessage (javax.mail.internet.MimeMessage)2 EmailException (org.pmiops.workbench.exceptions.EmailException)2