Class MailgunEmailClient

java.lang.Object
formflow.library.email.MailgunEmailClient
All Implemented Interfaces:
EmailClient<com.mailgun.model.message.MessageResponse>

@Component public class MailgunEmailClient extends Object implements EmailClient<com.mailgun.model.message.MessageResponse>
This implementation of EmailClient sends email through Mailgun.
  • Constructor Details

    • MailgunEmailClient

      public MailgunEmailClient(@Value("${form-flow.email-client.mailgun.sender-email:}") String senderEmail, @Value("${form-flow.email-client.mailgun.domain:}") String mailgunDomain, @Value("${form-flow.email-client.mailgun.key:}") String mailgunKey)
      Constructor for the MailgunEmailClient class.
      Parameters:
      senderEmail - Email account that messages will be sent from
      mailgunDomain - Domain name that messages will be sent from
      mailgunKey - Mailgun API key
  • Method Details

    • sendEmail

      public com.mailgun.model.message.MessageResponse sendEmail(String subject, String recipientEmail, String emailBody)
      This sends an email with the least amount of information needed to be provided. Sets empty or defaults to the rest of the parameters.
      Specified by:
      sendEmail in interface EmailClient<com.mailgun.model.message.MessageResponse>
      Parameters:
      subject - The subject line of the email
      recipientEmail - The email address that will get the email, aka the To field
      emailBody - The HTML version of the email body
      Returns:
      A Mailgun MessageResponse object
    • sendEmail

      public com.mailgun.model.message.MessageResponse sendEmail(String subject, String recipientEmail, String emailBody, List<File> attachments)
      This sends an email with the least amount of information needed to be provided, but with attachments. Sets empty or defaults to the rest of the parameters.
      Specified by:
      sendEmail in interface EmailClient<com.mailgun.model.message.MessageResponse>
      Parameters:
      subject - The subject line of the email
      recipientEmail - The email address that will get the email, aka the To field
      emailBody - The HTML version of the email body
      attachments - A list of files that will be added as attachments to the email
      Returns:
      A Mailgun MessageResponse object
    • sendEmail

      public com.mailgun.model.message.MessageResponse sendEmail(String subject, String recipientEmail, List<String> emailsToCC, List<String> emailsToBCC, String emailBody, List<File> attachments)
      The main method that sends to Mailgun. Allows all parameter customization.
      Specified by:
      sendEmail in interface EmailClient<com.mailgun.model.message.MessageResponse>
      Parameters:
      subject - The subject line of the email
      recipientEmail - The email address that will get the email, aka the To field
      emailsToCC - A list of emails to be added into the CC field
      emailsToBCC - A list of emails to be added into the BCC field
      emailBody - The HTML version of the email body
      attachments - A list of files that will be added as attachments to the email
      Returns:
      A Mailgun MessageResponse object
    • setMailgunMessagesApi

      public void setMailgunMessagesApi(com.mailgun.api.v3.MailgunMessagesApi mailgunMessageApi)
      This setter allows us to replace mailgunMessageApi with a mock for testing.
      Parameters:
      mailgunMessageApi - The mailgunMessageApi you want to use to interface with Mailgun.
    • setSenderEmail

      public void setSenderEmail(String senderEmail)
      This setter allows you to change the senderEmail. By default, senderEmail is defined in application.yaml.
      Parameters:
      senderEmail - The email that is used to fill the from field.
    • setRequireTls

      public void setRequireTls(Boolean requireTls)
      This setter allows to change requireTls from its default setting of true
      Specified by:
      setRequireTls in interface EmailClient<com.mailgun.model.message.MessageResponse>
      Parameters:
      requireTls - Is a Boolean that sets requireTls for the message sent to mailgun.