How to use Papercut with java mail API

Are you looking for a way to use Papercut with java mail API? If so, then I will share the method I stumbled upon while searching for the same.

As a software developer, I too got stuck with this problem. I had to check and verify whether the mail content is in place while sending a mail using JAVA mail API. During Development phase we cannot send the mail directly to someone. We have to make sure that the mail is presentable to the end user. The code for java mail is as shown below

The code above can be altered as per your need. The mail is sent flawlessly, when the following line of code executes.

But we need to verify the formatting. For this, just install the Papercut server.
After installing the server you have to include one more line of code to the java mailing code.
Change the code to

Default port for Papercut is set as 25. That’s why we are setting the port as 25 so that all the mail which we are sending from java mail will go to this Papercut server and we can view the mail in this.

You have to make sure that these code should be used only during the time of development. You have to remove the port which we set in the java mail code to get it work. Hope this helps.

Share this article: