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 0.0.0.5 - Added the following Beta 0.0.0.4 - Fixed/Changed the following Beta 0.0.0.3 - Still a bit rough around the edges with very little parameter validation (also changed project name to Send2SMTP)

Background

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.

Usage

The following section shows some basic usage examples.

Send a single email from me@mydomain.com to you@mydomain.com via SMTP server hosted on 'MyHost' with default subject & body text

Send2SMTP -host MyHost -from me@mydomain -to you@mydomain.com

Send 10 emails to me@mydomain.com via email server hosted on 'MyHost' with default subject & body from 'another@mydomain.com'

Send2SMTP -host MyHost -to me@mydomain.com -copies 10 -from another@mydomain.com

Send 100 emails to you@mydomain.com 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 me@mydomain.com -to you@mydomain.com -copies 100 -attachdir c:\MyAttachments -attachprob 10

Send 10000 emails to me@mydomain.com 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 me@mydomain.com -to you@mydomain.com -copies 10000 -subject "Message:%MESSAGENUM() Sent %DATETIME()"

Option Reference

Here's a list of all the available options

Option Description and ExampleRequired
-host, -hIdentifies the host SMTP server. E.g. -host MyServer or -host 10.0.0.1 Yes
-from, -fIdentifies the sender of the email. E.g. -from me@mydomain.com Yes
-to, -cc, -bccAddress of the 'To', 'CC' and 'BCC' recipient of the emails. E.g. -to PaulJ@SampleXYZ1.com Yes (No if file version used)
-tofile, -ccfile, -bccfileUsed 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.txtNo
-port, -pPort to use to connect to SMTP server (default 25). E.g. -port 1010 No
-copies, -cpNumber of emails to send. E.g.-copies 1000No
-subject, -sSubject used for each mail. E.g. -subject "Test message"No
-attach, -aUsed to specify an attachment file. Multiple attachments can be specified. E.g. -attach "C:\MyTestFile1.txt" -attach "C:\MyTestFile2.txt"No
-attachdir, -adIndicates the directory used to source all attachments (alternative to using -attachdir). E.g -attachdir C:\MyAttachmentsNo
-randomattachments, -raUse 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, -apUsed 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 10No
-body, -bBody text for each message. Only one body option can be specified. E.g. -body "This is the body text" No
-bodyfile, -bfSpecifies the 'body' element of a message via a file (alternative to -body) E.g. -bodyfile C:\MyBodyFile.txt No
-bodyishtm, -bhtmlUsed to indicate that the body text is HTML. E.g. -bodyishtml true No
-threads, -thUsed to specify the number of threads that Send2SMTP will create to send messages. The default is 5. E.g. -threads 10No
-seedUsed 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
-credsUsed 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 MyDomain.comNo
-delayUsed 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 1500No

Macros

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 DescriptionSubjectBody
%MESSAGENUM()Displays the current unique message number. This number always starts from 1 and increases until the total number of messages has been generated._YesYes
%DATETIME()Displays the current date & time.YesYes
%THREADID()Displays the thread Id that generated this message (threads are numbered from 0 and increase sequentially).YesYes
%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.NoYes
%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) http://en.wikipedia.org/wiki/Basic_Multilingual_PlaneNoYes
%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..YesYes

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 -

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.