/
Mailgun API

Mailgun API

Instructions

  1. If you do not have an account register on https://signup.mailgun.com/new/signup

  2. Activate your account by clicking on the link in the verification email send to you.

  3. In your Mailgun app click on Sending > Domains in the left menu

  4. Select your sandbox domain

  5. In the “Authorized Recipients” card add your email and click Save Recipient. Verification mail will be sent to that email address and recipient must agree to receiving emails.

  6. In domain overview click on SMTP and copy the following settings to your application properties:

    1. SMTP hostname to spring.mail.host

    2. Port to spring.mail.port

    3. Username to spring.mail.jndi-name.spring.mail.username

    4. Default password to spring.mail.jndi-name.spring.mail.password

  7. Test your connection by creating new Groovy runner (string "your@email.com" replace with the autorized recipients email address from step 5) and starting your app:

    @Component class TestMailRunner extends AbstractOrderedCommandLineRunner { @Autowired private IMailService mailService @Override void run(String... args) throws Exception { SimpleMailDraft draft = SimpleMailDraft.simpleMailDraftBuilder() .body("Test mail body") .isHtml(false) .subject("Test mail") .recipients(["your@email.com"]) .build() mailService.sendMail(draft) } }