Home  > Resources  > Blog

Running a Local SMTP Server

 
June 6, 2011 by Bibhas Bhattacharya

When developing applications that send out e-mails, it helps to run a local e-mail server. Java Email Server is a simple SMTP server perfect for unit testing.

Install

Download and extract the ZIP file somewhere, say C:\Program Files\JES.

Open the file bin/ntservice.bat using Notepad. Set the JES_HOME_DIR variable to the root of the install folder.

set JES_HOME_DIR=c:\Progra~1\JES

Set JDK_HOME_DIR to the root of Java. Note: You must point to a JDK directory and not a JRE.

set JDK_HOME_DIR=C:\Progra~1\IBM\SDP\runtimes\base_v7\java

If you are using IBM JDK, set the JDK_MODE to classic.

set JDK_MODE=classic

Save changes.

From the bin directory of JES, run this command to install the service:

ntservice.bat -install

image

Open Services control panel applet. Start JavaMailServer service to start the SMTP server.

Configure

Open mail.conf from the root folder. Set the local domain name:

domains=webagesolutions.com

Any e-mail sent to the local domain will be saved by this e-mail server (and will not be forwarded to the actual SMTP server of the domain). For example, if we set this to webagesolutions.com then e-mails sent to any address with @localhost domain will be considered local to this server and it will be saved right there. This is great because, you don’t want to send test e-mails to actual users. That will only confuse the recipients.

Set the default user’s e-mail:

defaultuser=admin@localhost

This comes very handy during development. You can send e-mails to any user with @localhost domain. All e-mails will be deposited to the default user’s box. This way, you can configure only one POP3 account in your mail program for the default user and pull out all e-mails using that.

Save and close mail.conf.

Open users.conf. Here, add the default user. The format is user.<username@domain>=<plain text password>. So, to add a user called "admin" with password "pass", do:

user.admin@localhost=pass

Save changes.

Restart the service.

Note: E-mails sent to non-local domain will be relayed by JES. Many ISPs block SMTP protocol to prevent spamming. For example, I can’t send e-mail to Gmail’s SMTP server without using my ISP’s SMTP server. Relaying might be hard to achieve. But, mails to local domain is guaranteed to work.

Configure Mail Reader

In your mail reader, configure POP3 as follows:

Hostname: localhost.
User ID: admin@localhost. You must enter the full domain name.
Password: pass

For SMTP server, enter localhost as the hostname.

Now, you will be to send e-mail to any user of the local domain. You can pick up all of those e-mails from the single POP3 user account.

Follow Us

Blog Categories