Package formflow.library.email
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 Summary
ConstructorsConstructorDescriptionMailgunEmailClient(String senderEmail, String mailgunDomain, String mailgunKey) Constructor for the MailgunEmailClient class. -
Method Summary
Modifier and TypeMethodDescriptioncom.mailgun.model.message.MessageResponseThis sends an email with the least amount of information needed to be provided.com.mailgun.model.message.MessageResponseThis sends an email with the least amount of information needed to be provided, but with attachments.com.mailgun.model.message.MessageResponsesendEmail(String subject, String recipientEmail, List<String> emailsToCC, List<String> emailsToBCC, String emailBody, List<File> attachments) The main method that sends to Mailgun.voidsetMailgunMessagesApi(com.mailgun.api.v3.MailgunMessagesApi mailgunMessageApi) This setter allows us to replace mailgunMessageApi with a mock for testing.voidsetRequireTls(Boolean requireTls) This setter allows to change requireTls from its default setting of truevoidsetSenderEmail(String senderEmail) This setter allows you to change the senderEmail.
-
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 frommailgunDomain- Domain name that messages will be sent frommailgunKey- 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:
sendEmailin interfaceEmailClient<com.mailgun.model.message.MessageResponse>- Parameters:
subject- The subject line of the emailrecipientEmail- The email address that will get the email, aka the To fieldemailBody- 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:
sendEmailin interfaceEmailClient<com.mailgun.model.message.MessageResponse>- Parameters:
subject- The subject line of the emailrecipientEmail- The email address that will get the email, aka the To fieldemailBody- The HTML version of the email bodyattachments- 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:
sendEmailin interfaceEmailClient<com.mailgun.model.message.MessageResponse>- Parameters:
subject- The subject line of the emailrecipientEmail- The email address that will get the email, aka the To fieldemailsToCC- A list of emails to be added into the CC fieldemailsToBCC- A list of emails to be added into the BCC fieldemailBody- The HTML version of the email bodyattachments- 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
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
This setter allows to change requireTls from its default setting of true- Specified by:
setRequireTlsin interfaceEmailClient<com.mailgun.model.message.MessageResponse>- Parameters:
requireTls- Is a Boolean that sets requireTls for the message sent to mailgun.
-