Method for email testing

2019-01-31 17:52发布

问题:

I am writing a program that will be emailing reports out many (~100) clients which I want to test before I spam everyone.

I want to do a test run against my production data and actually send the messages to a SMTP server, but I don't want the SMTP server to actually deliver the messages. I want the server to act like a real SMTP server from the perspective of my application, but instead of delivering messages, I just want it to store the messages, and log what happened.

Is there a SMTP server specifically designed for testing purposes?

Does anyone know of a way to configure exim or postfix to behave like I have described above

What do you use to test a mass-email delivery?

回答1:

In java you can use dumbster

Its easy to use and you can validate every aspect of the email you are intercepting.

It's a Java SMTP server implementation meant for unit testing. (Just make sure you redirect your email to the machine running dumbster...)


I just found another alternative that do almost the same: Greenmail

Greenmail also support POP3, IMAP with SSL so you can test your client against it.



回答2:

For .NET I set the config file to deliver mail to a folder, then you can have the automated test inspect the directory and files.

<system.net>
 <mailSettings>
  <smtp deliveryMethod="SpecifiedPickupDirectory">
   <specifiedPickupDirectory pickupDirectoryLocation="c:\pickupDirectory"/>
  </smtp>
 </mailSettings>
</system.net>


回答3:

While searching for options I found the following that may be useful.

  • DevNullSmtp
  • Use a null SMTP server for testing
  • Fake SMTP Service
  • twisted examples/emailserver.tac


回答4:

"The Wiser framework for unit testing mail"

I've heard of a few other developers moving from Dumbster to Wiser and have migrated my testing code as well. One of the Java components that I've worked on sends thousands of emails a day and I've written unit tests for the different email templates and scenarios using Dumbster and Wiser. I prefer Wiser.

Snips from the Wiser website (http://code.google.com/p/subethasmtp/wiki/Wiser):

Wiser is a smart replacement for Dumbster and is built on top of the SubEtha SMTP Java library which allows your Java application to receive SMTP mail with a simple, easy-to-understand API.



回答5:

A good program for email testing is smtp4dev (Windows only).

It's a dummy SMTP server. Sits in the system tray and does not deliver the received messages. The received messages can be quickly viewed, saved and the source/structure inspected.

http://smtp4dev.codeplex.com/



回答6:

http://skaraarslan.blogspot.com/2008/02/how-to-check-email-works-without-using.html

(this presumes you are using .net to send emails)



回答7:

Given that you mention exim and postfix (which I'm taking to be some kind of unix stuff), this answer might not be as useful as it could be, but check out Neptune. It's a fake SMTP server designed for automated testing. If you've got a spare windows box floating around, you could put Neptune on that then configure your app to send "through" the Neptune server.



回答8:

Exim can be configured to accept incoming mails but not deliver them. Look for the keywords queue_only and queue_only_file in the documentation.



回答9:

I personally modify the e-mail addresses to test, I send them to a dummy account of mine, that way I can validate not only that they sent, but that they appear in the proper format.



回答10:

At my office, we have a server that is set up to always send all incoming mail to one address, regardless of who it's actually addressed to. We just point all our testing environments at that server and watch the QA mailbox fill up. I don't know what server it is, but it's probably some open source thing someone found.



回答11:

Sendmail has a Test Mode.

You just invoke sendmail with the -bt parameter. As an example:

/usr/lib/sendmail -bt -Ciu-testconfiguration.cf

Please be aware that in this method, Sendmail requires an special configuration on rewrite rules. You need to understand how Sendmail rewrites addresses in order to properly create a .cf file for Test Mode.


Edit: See this article: http://ussg.iu.edu/usail/mail/debugging/



回答12:

After not beeing happy with the solutions I found, I ended up writing developmentSMTP, easy to use, 100% Java --> cross platform.

Supports writing emails to file, forwarding emails or simply printing them on stdout.



回答13:

Post Hoc is a pure Java application that looks exactly like an SMTP server to the application you are testing, but it simply collects all the email messages and allows you to inspect them using a web interface.

Freely available at: Post Hoc GitHub Site

For more information: PostHoc: Testing Apps that Send Email



回答14:

If you're looking to manually test that the email sends and that the email template has the right kind of html and css that you're expecting, then I would recommend maildev https://www.npmjs.com/package/maildev. You can install and run it as a node module and also as a docker container! I've found it extremely handy for basic sanity testing of emails.