48

I want to test a Java code for sending email. I don't want to use any commercial mail client or connect to any external mail providers (like Gmail or Yahoo). I would like to know if there is any software which allows a user to configure dummy email addresses and server (locally) which can be used in my software to send and receive mails. I just want to test the functionality of the Java code.

palacsint
  • 28,416
  • 10
  • 82
  • 109
sathish kumar
  • 1,187
  • 5
  • 17
  • 21

10 Answers10

28

For email testing, try Dumbster. From their page:

The Dumbster is a very simple fake SMTP server designed for unit and system testing applications that send email messages. It responds to all standard SMTP commands but does not deliver messages to the user. The messages are stored within the Dumbster for later extraction and verification.

The Dumbster slots itself very easily into your testing strategy. As long as your application talks to an email server using SMTP then the Dumbster can be used to test the application with no code changes.

Various forks exist since the original page is no longer available:

More can be found using a Github Search

Yanick Salzmann
  • 1,456
  • 1
  • 15
  • 27
Matthew Farwell
  • 60,889
  • 18
  • 128
  • 171
  • Ah, that's the other one I was trying to remember! I knew I'd recognize it as soon as I saw it, but I just couldn't come up with the name. – Argyle Dec 22 '11 at 05:38
  • 1
    Dumbster is [broken](http://sourceforge.net/p/dumbster/bugs/15/). – Markus Malkusch Jul 11 '14 at 22:44
  • _As a side note:_ there are [several _forks_](https://github.com/search?utf8=%E2%9C%93&q=dumbster&type=) of the original "Dumbster" that improve its functionality in different ways. – informatik01 Jun 06 '17 at 15:33
  • Could you update the link in this answer? The original one redirects to agoda (a hotel booking web site) now. https://github.com/kirviq/dumbster and https://github.com/rjo1970/dumbster both look promising to me but I haven't tried either of them yet. – Matthias Kauer Nov 05 '17 at 07:07
  • I found original link does not work anymore. Here there is a fork that works for me: https://github.com/kirviq/dumbster – alostale May 17 '18 at 12:05
  • try greenmail library! – Gaurav Feb 22 '19 at 18:42
  • I'm a little late for this question, but I just released smtp4j (https://github.com/ctabin/smtp4j) which is an improved API based on dumbster :-) – ctabin May 21 '21 at 14:36
19

I prefer Fake SMTP for this. It's a desktop app (packed into jar file). Since it is written in Java, you can run it both from Linux/Mac/Windows

Anton Shchastnyi
  • 3,812
  • 3
  • 20
  • 23
10

You can use Wiser in the SubEthaSMTP library, Wiser's purpose is exactly what you want, unit testing.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Hontvári Levente
  • 1,242
  • 10
  • 16
  • Wiser sample code: http://code.google.com/p/subethasmtp/wiki/Wiser – palacsint Jan 29 '14 at 16:36
  • Also broken, when my unit test sends 2 html emails wiser receives 3 somehow. GreenMail handles that correctly, fortunately. – okutane Mar 08 '17 at 06:32
  • okutane: I guess you sent two mails with three recipients in total. The Wiser API returns mails by recipients. It is indeed not in the last released version, but the trunk contains an updated JavaDoc to make this more obvious: "The number of mail transactions and the number of mails may be different. If a message is received with multiple recipients in a single mail transaction, then the list will contain more WiserMessage instances, one for each recipient." – Hontvári Levente Mar 13 '17 at 12:18
  • @HontváriLevente: no, that wasn't the case. – okutane Mar 22 '17 at 11:29
9

Try GreenMail. It's geared towards JUnit usage, but it should do what you need. You can run it in a JBoss instance or have your JUnit tests send mail to themselves, depending on your specific needs.

There are a few other similar bits of software out there, but that's the one I've used and was reasonably happy with it.

Argyle
  • 3,324
  • 25
  • 44
3

on Leopard you can start a Local SMTP Server (Postfix) on OS-X Leopard

sudo vi /System/Library/LaunchDaemons/org.postfix.master.plist

before the closing tag at the end:

<key>RunAtLoad</key> <true/> <key>KeepAlive</key> <true/>

then start the thing with

sudo postfix start

now you check wheter the service is running with:

telnet localhost 25
thegrunt
  • 1,054
  • 1
  • 11
  • 22
3

The javamail-file-transport saves emails to files instead of sending them through SMTP server.

See the javaMail extensions project on GitHub.

It adds file transport that allows:

  • save mails to files in text format instead of sending them
  • save mails to files in mbox format instead of sending them
  • add log info instead of sending email
m-szalik
  • 3,546
  • 1
  • 21
  • 28
3

I've used Mailtrap a few times, and I can recommend it.

tomaj
  • 1,570
  • 1
  • 18
  • 32
1

Option A.
amazing docker
https://hub.docker.com/r/mailhog/mailhog/
(gitHub - https://github.com/mailhog/MailHog)
This docker has two ports:
One port for sending SMTP e-mails (smtp://0.0.0.0:1025/)
A second port to the e-mail display on the web (http://0.0.0.0:8025/)

run docker:
docker pull mailhog/mailhog
docker run --name=mailhog -d -p 1025:1025 -p 8025:8025 mailhog/mailhog

Option B.
if you use with bamboo.mailer
add adapter: Bamboo.LocalAdapter
see Bamboo.SentEmailViewerPlug.

hana9
  • 141
  • 1
  • 5
  • see [A Test Mail Server for a PHP Docker Container](https://blog.philipphauer.de/test-mail-server-php-docker-container/) – mancocapac Jun 05 '18 at 18:59
0

You can use smtp4dev. Please find out more details here.

Amit Gupta
  • 23
  • 8
0

use the Aspirin From the docs: Aspirin is an embeddable send-only SMTP server for Java developers.