This project is read-only.

Project Description

Send2SMTP is a simple console application that will generate and send random email messages to a given SMTP server. The primary use is for developers/ administrators working in email systems who need to generate test messages with various characteristics. It's developed in C#.

Release History

Beta - Added the following
  • Added the -ssl switch to allow working with GMail and other services which require SSL/TLS (by kjhughes097)
Beta - Fixed/Changed the following
  • Removed '-randomwords' option. The range for random words is now specified in the %RANDOMTEXT macro (see below)
  • Modified %RANDOMTEXT macro. It now takes two parameters, %RANDOMWORDS(min,max). During evaluation it will expand to a random string of words between min and max
  • Added a better macro handler
  • Added the following new macros (see documentation below for more details)
    • %UNICODETABLE(startCP,stopCP,autoincrement) - When evaluated it will produce a table of unicode characters.
    • %UNICODECHAR(startCP,autoincrement) - When evaluated outputs a single unicode character.
    • %RANDOMTEXT(min,max) - Added two parameters to this macro (previously they were specified with the '-randomwords' option). If you currently use this macro then this build will break it and you'll need to update it accordingly.
  • Added three new options '-tofile', '-ccfile' and '-bccfile' that allows you to load recipient data via a file rather than through the command line (see option table below).
Beta - Still a bit rough around the edges with very little parameter validation (also changed project name to Send2SMTP)


This application started out as a simple utility I wrote to generate email messages to test our email processing software (where I currently work). There are several examples of such utilities out there (I found a few on CodePlex), but initially I needed to generate message with certain characteristics (e.g Messages containg random sequences of english words of a certain length etc...). So I started writing this app. Over the weeks I've added various features as my requirements changed (e.g Macro expansion). It's now at a point where it might be useful for someone else so I've decided to publish it here. If you find it useful, or indeed need additional features let me know via the Issue Tracker/Discussion tabs.


The following section shows some basic usage examples.

Send a single email from to via SMTP server hosted on 'MyHost' with default subject & body text

Send2SMTP -host MyHost -from me@mydomain -to

Send 10 emails to via email server hosted on 'MyHost' with default subject & body from ''

Send2SMTP -host MyHost -to -copies 10 -from

Send 100 emails to via email server hosted on 'MyHost' with default subject & body with attachments sourced from the directory 'C:\MyAttachments'. The attachment-probability is set to 10 which means Send2SMTP will attempt to send 10% of its messages with attachments. Each message that contains an attachment will have between 1 to 3 attachments from the source directory (this range can be changed).

Send2SMTP -host MyHost -from -to -copies 100 -attachdir c:\MyAttachments -attachprob 10

Send 10000 emails to via email server hosted on 'MyHost' with a subject of 'Message:XXXX Sent YYYY'. E.g 'Message:1025 Sent 03/03/2009 16:48:00'.

Send2SMTP -host MyHost -from -to -copies 10000 -subject "Message:%MESSAGENUM() Sent %DATETIME()"

Option Reference

Here's a list of all the available options

Option Description and Example Required
-host, -h Identifies the host SMTP server. E.g. -host MyServer or -host Yes
-from, -f Identifies the sender of the email. E.g. -from Yes
-to, -cc, -bcc Address of the 'To', 'CC' and 'BCC' recipient of the emails. E.g. -to Yes (No if file version used)
-tofile, -ccfile, -bccfile Used to indicate a file that contains the 'To','CC' and 'BCC' recipient list respectively (specify each recipient on a separate line within the file). E.g -tofile MyToList.txt No
-port, -p Port to use to connect to SMTP server (default 25). E.g. -port 1010 No
-copies, -cp Number of emails to send. E.g.-copies 1000 No
-subject, -s Subject used for each mail. E.g. -subject "Test message" No
-attach, -a Used to specify an attachment file. Multiple attachments can be specified. E.g. -attach "C:\MyTestFile1.txt" -attach "C:\MyTestFile2.txt" No
-attachdir, -ad Indicates the directory used to source all attachments (alternative to using -attachdir). E.g -attachdir C:\MyAttachments No
-randomattachments, -ra Use this option to control the number of attachments (between min,max) that each message can have. The default is 1 and 3 respectively which means that each message that is designated to contain an attachment will have between 1 and 3 attachments. E.g. -randomattachments 2 5 No
-attachprob, -ap Used to specify the probability that a message will contain an attachment. The number ranges from 0 to 100. A value of 0 means none of the message contain attachments (default). A value of 100 means all message contain attachments. A value of 20 means 20% of the messages will contain an attachment. If you want attachments with your messages then this option must be set. E.g -attachprob 10 No
-body, -b Body text for each message. Only one body option can be specified. E.g. -body "This is the body text" No
-bodyfile, -bf Specifies the 'body' element of a message via a file (alternative to -body) E.g. -bodyfile C:\MyBodyFile.txt No
-bodyishtm, -bhtml Used to indicate that the body text is HTML. E.g. -bodyishtml true No
-threads, -th Used to specify the number of threads that Send2SMTP will create to send messages. The default is 5. E.g. -threads 10 No
-seed Used to specify the random number seed (postive integer). Default is -1 which means the current tick count is used to seed the random sequence. Any other number will guarantee a repetable sequence. This is useful if you need to generate exactly the same set of random emails again and again. E.g. -seed 100 No
-creds Used to supply credentials (username password domain) if your SMTP server requires them. By default Send2SMTP will use your current network credentials. E.g. -creds me password No
-delay Used to introduce a delay (in ms) between each message that is sent (per thread). Usefull if you want to drip feed messages to an SMTP server over a long period of time without completely swamping the network. Default is 0ms. E.g -delay 1500 No


You have the ability to inject various predefined text into the subject and body of each message that is generated. This is achieved through a simple macro substition. To use a macro simply include its name within either the subject or body text. For example, the following macro

This is message number %MESSAGENUM()

would be expanded out to (assuming the next message number was 24)

This is message number 24

The following table shows the current set of macros that can be used. Note: This new version requires the brackets for each macro to work correctly.

Macro Description Subject Body
%MESSAGENUM() Displays the current unique message number. This number always starts from 1 and increases until the total number of messages has been generated._ Yes Yes
%DATETIME() Displays the current date & time. Yes Yes
%THREADID() Displays the thread Id that generated this message (threads are numbered from 0 and increase sequentially). Yes Yes
%RANDOMTEXT(min,max) Displays a random string of english words taken from an 80,000 word dictionary. The number of words generated varies for each message. The range of variation is set by 'min' and 'max' parameters. For example, %RANDOMTEXT(10,50) would evaluate to a string of words between 10 and 50. No Yes
%UNICODETABLE(startCP,stopCP,autoIncrement) Generates a simple table of unicode characters in the range [startCp,stopCP] (the parameters are assumed to be in hex). If 'autoincrement' parameter is set to true, each evaluation will output another block of unicode characters starting from 'stopCP+1'. For example, %UNICODETABLE(0,FF,true) will generate a table from U+0000 to U+00FF. The next message will then output a table from U+0100 to U+01FF etc.. This macro is useful if you need to test specific character sets. For example, if you need to output the entire Thai script, use %UNICODETABLE(0E00,0E7F,false). Assuming you have this typeface installed on your computer you'll then see these characters in the generated email. The following Wikipedia link has a comprehensive listing of the Basic Multilingual Plane (BMP) No Yes
%UNICODECHAR(startCP,autoIncrement) Outputs a single unicode character starting from the 'startCP'. If 'autoIncrement' is set to true then each subsequent message will output the next unicode character. For example, %UNICODECHAR(41,true) will output 'A' for the first message, 'B' for the second etc.. Yes Yes

Random Numbers

A note about the random number generator - Send2SMTP can be used to generate exactly the same set of random emails if you use the -seed option. This option is useful if, for example, you're doing performance testing in your mail environment and want to benchmark configuration changes with exactly the same set of emails.

There are however a few limitations to this -
  • Each mail generated will have a different 'delivery time' etc.. These attributes cannot be regenerated with each successive call of Send2SMTP
  • If you use macros such as %DATETIME anywhere in your mail (i.e. subject and/or body) then the text in each mail will be different with each successive call of Send2SMTP. If you need to 'excactly' the same set of emails (i.e. identical subject & body text) then avoid using time variant macros such as %DATETIME
  • Because Send2SMTP uses SMTP it's highly likely that under the hood there will also be other differences to each message that cannot be reproduced reliably because of the way SMTP routers add various message headers to each message they process.

If you're using Send2SMTP for basic system performance testing etc.. then most of these limitiations won't be a problem.

Future Enhancements

At the moment I have no further enhancements planned as this utility now addresses my requirements (and hopefully some of yours). Feel free to raise an issue/discussion if you think there's something else you'd like.

Last edited Mar 14, 2013 at 6:12 PM by PaulJones, version 87