How to test a mail service without SMTP-server (Java)

To test if a mail was successfully sent using Java you would normally need an SMTP-server to check. If it happens that you don’t have a server available, you can use mailtrap. To setup mailtrap, following code is used: Properties prop = new Properties(); prop.put("mail.smtp.auth", true); prop.put("mail.smtp.starttls.enable", "true"); prop.put("", ""); prop.put("mail.smtp.port", "25"); prop.put("", ""); session = Session.getInstance(prop, new Authenticator() { @Override protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication("YYY", "XXX"); } }); Mails sent using this session token end up in webservice that you can check.

How to test a mail server?

Which steps have to be done to manually send an email using the SMTP protocol? This can be useful to check after setup if a mailserver is configured properly.


Subscribe to SMTP