Send email from Spring Boot over SMTP

Set Spring Mail properties to Unitpost SMTP and send with JavaMailSender. Port 587, STARTTLS, username `unitpost`.

What are the SMTP settings?

Hostsmtp.unitpost.com
Usernameunitpost(always this literal value)
PasswordYour Unitpost API key(must carry emails:send)
Port (STARTTLS)587(or 2587 if blocked)
Port (implicit TLS)465(or 2465 if blocked)
From addressAny address on a verified domain

How do I set it up?

  1. Set mail properties

    Properties
    spring.mail.host=smtp.unitpost.com
    spring.mail.port=587
    spring.mail.username=unitpost
    spring.mail.password=${UNITPOST_API_KEY}
    spring.mail.properties.mail.smtp.auth=true
    spring.mail.properties.mail.smtp.starttls.enable=true
  2. Send with JavaMailSender

    Java
    MimeMessage message = mailSender.createMimeMessage();
    MimeMessageHelper helper = new MimeMessageHelper(message, true);
    helper.setFrom("you@yourdomain.com");
    helper.setTo("customer@example.com");
    helper.setSubject("Hello from Spring");
    helper.setText("<p>Sent via SMTP.</p>", true);
    mailSender.send(message);
  3. Verify delivery

    Check Activity.