-
Notifications
You must be signed in to change notification settings - Fork 0
HOWTO: Using pseudoSMTP
So you've deployed the app and it's running. Now what? With psmtp you have two components.
First, you now have an SMTP server ready to accept incoming mail. Any app(s) you're testing that produce and send email should be configured to send their mail through psmtp's smtp server. Then get your app to start sending mail. Once something sends mail to psmtp's server then you can go searching for it via the REST API. Remember, psmtp's smtp server is not a real smtp server! It will never ever try to deliver the email it receives to the listed recipients. The whole purpose of psmtp is to capture the email and allow it to be validated through unit, functional, acceptance, etc. testing.
Even though the smtp server is not real in the sense that it doesn't deliver email to the intended recipients, it is completely real in the sense that it supports the smtp protocol, including 8bit MIME messages, attachments, etc. Everything about the smtp server is real, except that it doesn't deliver messages, but instead stores them in a database for inspection and validation within a testing environment. More details about the smtp server are available in the SMTP FAQ.
The only way to access the mail sent through psmtp's smtp server is to search for it and download it via psmtp's REST API.
The second component to psmtp is its REST API. All mail received by the smtp server is stored in a database and exposed only through this REST API. You can access all emails received by psmtp via this API. The API also provides filtering capabilities. The basic idea is that you request a list of emails of interest from the REST API, it returns a list of matching emails then you can download the complete MIME message and validate it as you see fit.
All emails are stored as fully compliant MIME email messages. When you request a complete message from the API, the response is the complete MIME message binary stream suitable for parsing and processing with your favourite MIME email library. If you're a Java shop then that usually means using the JavaMail APIs. The stream returned by the API is fully compliant for use with JavaMail's MimeMessage
constructor.
Details on using the REST API are documented in the REST API wiki page and the REST API FAQ.
Starting with v0.2.0, there is a basic web viewer available that displays the basic metadata of all messages stored for a given client scope.
Visit /inbox.groovy
to load the viewer. You will be prompted for the host/IP of the client scope -- this is the host that is sending the email to psmtp (i.e. your application under test).
Again, this is a very basic viewer with minimal functionality. It was created out of a need to not want to try and manually parse raw json while debugging issues. If you need additional features, please open tickets.