{"id":41727,"date":"2016-10-24T14:15:26","date_gmt":"2016-10-24T08:45:26","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=41727"},"modified":"2016-12-19T15:04:04","modified_gmt":"2016-12-19T09:34:04","slug":"setting-up-smtp-server-with-gui-for-testing-purpose","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/setting-up-smtp-server-with-gui-for-testing-purpose\/","title":{"rendered":"Setting up SMTP Server with GUI for Testing purpose"},"content":{"rendered":"<p><span style=\"font-weight: 400;\">Setting up SMTP server with GUI is needed for testing emails in applications. This setup not only prevents the mails from delivering to the email addresses but also sends the emails to invalid email addresses.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">I have come up with a scenario where I have to setup an SMTP server for the testing purpose in the development environment. This requires \u00a0the web application to be configured, so that the <a title=\"devops developer\" href=\"http:\/\/www.tothenew.com\/devops-automation-consulting\">developers<\/a> and testers could test their application by sending email to different people. Previously, they were using Gmail account to send the emails. The emails were either delivering to the same email account or they have to login to different receiver email account to check if the mail is delivered successfully. To handle this scenario, GUI was required along with a fake SMTP server so that all the sent emails can be gathered at a central place.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">The solution was to set up an SMTP server with following added advantages:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">GUI console for aggregating all send emails.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Simple and easy to set up on developer\u2019s machine.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Simple and easy to configure.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Open source and free of cost.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Preferably available cross-platform.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">To be set up on a local network to avoid\u00a0any network related issues.<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">There are many open source fake SMTP servers that are available in the market which are designed for unit and system testing to send emails. Some popular fake SMTP servers are:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Greenmail<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">MailDev<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">FakeSMTP<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Dumbster<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">In my blog, I will brief you about <\/span><b>Greenmail <\/b><span style=\"font-weight: 400;\">and <\/span><b>MailDev<\/b><span style=\"font-weight: 400;\"> SMTP servers. These are easy to setup and configure.<\/span><\/p>\n<h1><span style=\"font-weight: 400;\">Greenmail:<\/span><\/h1>\n<ul>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">It is an open source, intuitive and easy-to-use test suite of email servers for testing purposes. <\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">It supports different protocols like SMTP, IMAP and POP3. <\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">It can be easily integrated into JUnit Tests.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">It provides the different ways for setup: running jar as a standalone JVM process, running war as a WAR module , running container from a docker image or running as a JBOSS service.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">The JBOSS service provides you with a GUI while the other two set up process don&#8217;t provide a GUI.<\/span><\/li>\n<\/ul>\n<p><b>Docker image:<\/b><\/p>\n<ul>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">It also provides a preconfigured docker image to launch the service as a standalone application. The docker container will launch the standalone greenmail application and it will be working on the following ports:<\/span>\n<ul>\n<ul>\n<ul>\n<ul>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">SMTP port: \u00a0\u00a03025<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">SMTPS port: 3465<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">IMAP port: \u00a0\u00a0\u00a03143<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">IMAPS port: \u00a03993<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">POP port: \u00a0\u00a0\u00a0\u00a03110<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">POP3s port: 3995 <\/span><\/li>\n<\/ul>\n<\/ul>\n<\/ul>\n<\/ul>\n<\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">The ports can be mapped across the host and the docker container so that the application can start using the protocols.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">The following commands can be used to launch the docker container as a standalone application:<\/span><\/li>\n<\/ul>\n<pre>docker pull greenmail\/standalone:1.5.2\r\ndocker run -t -i -d -p 3143:3143 -p 3025:3025 -p 3110:3110 -p 3995:3995 -p 3465:3465 -p 3993:3993 greenmail\/standalone<strong><strong>\u00a0<\/strong><\/strong><\/pre>\n<ul>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">It will run the docker container and will provide you with a container id.<\/span><\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p><b>JBOSS service:<\/b><\/p>\n<ul>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">The application can be integrated with JBOSS application server. Each developer will have its own local mail server and thus the emails will not be sent to the recipient addresses.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">The JBOSS service also provides you with a JMX console which will be integrated with greenmail plugin.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">To set up the application as a JBOSS service, you need to install JBOSS version 6 into your host.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">To install JBOSS 6 on the host follow the below steps:<\/span>\n<ul>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Download the JBOSS 6 zip file from the source.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Unzip the downloaded zip file into \/usr\/local directory.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Install jdk version 7 onto the host.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Create directory greenmail-jboss-service.sar at $JBOSS_HOME\/server\/default\/deploy<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Download the greenmail sar from <\/span><span style=\"font-weight: 400;\">http:\/\/www.icegreen.com\/greenmail\/#download<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Unjar the sar at $JBOSS_HOME\/server\/default\/deploy\/greenmail-jboss-service.sar<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Execute the script run.sh present at \/usr\/local\/jboss\/bin with parameter -b 0.0.0.0<\/span><\/li>\n<\/ul>\n<\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">To execute the above steps, run the following commands:<\/span><\/li>\n<\/ul>\n<pre><span style=\"font-weight: 400;\">wget -O ~\/jboss-as-distribution-6.0.0.Final.zip <\/span><span style=\"font-weight: 400;\">http:\/\/sourceforge.net\/projects\/jboss\/files\/JBoss\/JBoss-6.0.0.Final\/jboss-as-distribution-6.0.0.Final.zip\/download<\/span>\r\n<span style=\"font-weight: 400;\">unzip ~\/jboss-as-distribution-6.0.0.Final.zip -d \/usr\/local\/<\/span>\r\n<span style=\"font-weight: 400;\">mkdir \/usr\/local\/jboss\/server\/default\/deploy\/greenmail-jboss-service.sar<\/span>\r\n<span style=\"font-weight: 400;\">cd \/usr\/local\/jboss\/server\/default\/deploy\/greenmail-jboss-service.sar<\/span>\r\n<span style=\"font-weight: 400;\">cd ..<\/span>\r\n<span style=\"font-weight: 400;\">wget \/usr\/local\/jboss\/server\/default\/deploy\/greenmail-jboss-service.sar<\/span>\r\n<span style=\"font-weight: 400;\">unzip \/usr\/local\/jboss\/server\/default\/deploy\/greenmail-jboss-service.sar -c \/tmp\/<\/span>\r\n<span style=\"font-weight: 400;\">cp \/tmp\/greenmail-jboss-service.jar \/usr\/local\/jboss\/server\/default\/deploy\/greenmail-jboss-service.sar\/<\/span>\r\n<span style=\"font-weight: 400;\">sudo add-apt-repository ppa:webupd8team\/java<\/span>\r\n<span style=\"font-weight: 400;\">sudo apt-get update<\/span>\r\n<span style=\"font-weight: 400;\">sudo apt-get install oracle-java7-installer<\/span>\r\n<span style=\"font-weight: 400;\">.\/usr\/local\/jboss\/bin\/run.sh -b 0.0.0.0<\/span><\/pre>\n<ul>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">After setting up the JBOSS service, the JMX console will open at port 8080 <\/span><span style=\"font-weight: 400;\">http:\/\/localhost:8080\/jmx-console\/<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">The jmx-console will be opened as shown:<\/span><\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<div id=\"attachment_41728\" style=\"width: 310px\" class=\"wp-caption alignnone\"><img aria-describedby=\"caption-attachment-41728\" decoding=\"async\" loading=\"lazy\" class=\"size-medium wp-image-41728\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/10\/Screen-Shot-2016-10-23-at-12.03.44-PM-300x185.png\" alt=\"JMX console JBOSS\" width=\"300\" height=\"185\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2016\/10\/Screen-Shot-2016-10-23-at-12.03.44-PM-300x185.png 300w, \/blog\/wp-ttn-blog\/uploads\/2016\/10\/Screen-Shot-2016-10-23-at-12.03.44-PM-1024x633.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2016\/10\/Screen-Shot-2016-10-23-at-12.03.44-PM-624x385.png 624w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><p id=\"caption-attachment-41728\" class=\"wp-caption-text\">JMX console JBOSS<\/p><\/div>\n<ul>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Click on <\/span><span style=\"font-weight: 400;\">name=GreenMail,type=service,version=1.5.2<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">A new console will be opened as shown:<\/span><\/li>\n<\/ul>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-medium wp-image-41729\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/10\/Screen-Shot-2016-10-23-at-12.05.44-PM-300x95.png\" alt=\"Screen Shot 2016-10-23 at 12.05.44 PM\" width=\"300\" height=\"95\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2016\/10\/Screen-Shot-2016-10-23-at-12.05.44-PM-300x95.png 300w, \/blog\/wp-ttn-blog\/uploads\/2016\/10\/Screen-Shot-2016-10-23-at-12.05.44-PM-1024x325.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2016\/10\/Screen-Shot-2016-10-23-at-12.05.44-PM-624x198.png 624w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/p>\n<ul>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Here under <\/span><b>sendMail <\/b><span style=\"font-weight: 400;\">you can specify theTo, theFrom, theSubject and theBody to send emails.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Under <\/span><b>listMailsforUserHTML <\/b><span style=\"font-weight: 400;\">you can retrieve the email addresses by entering the email.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">You can configure your application to send emails using JBOSS SMTP protocol and retrieve them using the jmx-console.<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">The one cons of using Greenmail was to set up the JBOSS environment for sending the emails and retrieving them using the GUI. MailDev email server helps us in this situation by providing a docker image and binding them automatically to the host ports.<\/span><\/p>\n<p>&nbsp;<\/p>\n<h1><span style=\"font-weight: 400;\">MailDev<\/span><\/h1>\n<ul>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">MailDev is an another SMTP server which can be used for testing purpose. <\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">It provides an easy to use web interface that runs on your machine.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">It allows us to send and receive emails with attachments.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">The emails will not be delivered to the recipient addresses and will be aggregated at a central place.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">It also provides a command line interface for configuring SMTP applications.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">MailDev can be set up using node js and docker image.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">To install docker image and running docker container, run the followig commands:<\/span>\n<ul>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">docker pull djfarrelly\/maildev<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">docker run -p 1080:80 -p 1025:25 djfarrelly\/maildev<\/span><\/li>\n<\/ul>\n<\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">After running the container, the MailDev application will start running.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">SMTP will be running on port 1025 of your host.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Web UI will be running on 1080 port of your host.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">All send emails via SMTP will be aggregated and can be viewed in the console.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">The GUI will look as follows:<\/span><\/li>\n<\/ul>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-medium wp-image-41730\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/10\/Screen-Shot-2016-10-23-at-5.06.22-PM-300x134.png\" alt=\"Screen Shot 2016-10-23 at 5.06.22 PM\" width=\"300\" height=\"134\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2016\/10\/Screen-Shot-2016-10-23-at-5.06.22-PM-300x134.png 300w, \/blog\/wp-ttn-blog\/uploads\/2016\/10\/Screen-Shot-2016-10-23-at-5.06.22-PM-1024x457.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2016\/10\/Screen-Shot-2016-10-23-at-5.06.22-PM-624x278.png 624w, \/blog\/wp-ttn-blog\/uploads\/2016\/10\/Screen-Shot-2016-10-23-at-5.06.22-PM.png 1866w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>There are many such SMTP tools available in the market which are <a title=\"automated testing services\" href=\"http:\/\/www.tothenew.com\/testing\/automated-independent-manual-testing\">used for testing purposes<\/a>. I started with the aim of setting up such an SMTP server with a GUI console and didn&#8217;t need the mails to be in relay. You can use either of the above tools or any other popular tool depending upon your use case.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Setting up SMTP server with GUI is needed for testing emails in applications. This setup not only prevents the mails from delivering to the email addresses but also sends the emails to invalid email addresses. I have come up with a scenario where I have to setup an SMTP server for the testing purpose in [&hellip;]<\/p>\n","protected":false},"author":163,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":108},"categories":[2348,1],"tags":[1892,2774],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/41727"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/163"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=41727"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/41727\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=41727"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=41727"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=41727"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}