Swaks - Swiss Army Knife for SMTP
A scriptable, transaction-oriented SMTP test tool


Occasionally Asked Questions

These are questions that I occasionally get asked or I see pop up in a Google query string.

If you are trying to figure out something using Swaks, drop me a line at proj-swaks@jetmore.net. Swaks is a low-traffic project and I enjoy making it better, whether it's docs or code or just giving a hint in an email.

return to main page


Table of Contents
  1. How do I use Swaks to send email to multiple recipients?
  2. How do I add a header?
  3. How do I install on Mac OS X?
  4. How do I install on Windows?
  5. How do I send HTML email?
  6. Does Swaks support IPv6?

Multiple Recipients How do I use Swaks to send email to multiple recipients?

Multiple recipients can be specified by passing them as a single argument to the "--to" option. Any of the following will result in mail being sent to both foo@example.net and bar@example.com:

Command line:

swaks --to foo@example.net,bar@example.com

Environment variable:

SWAKS_OPT_to='foo@example.net,bar@example.com'
swaks

Config file:

echo "--to foo@example.net,bar@example.com" >> .swaksrc
swaks --config .swaksrc
The argument to the --to option is passed deep into the heart of Swaks with no real validation checking. This is done intentionally - because Swaks is meant to be a test tool, oddball values should be allowed. One side effect of this is that including a space after the comma will result in an email address that starts with a comma, which is probably not what you want.

There is one additional consideration here. Since Swaks is oriented around a single smtp-session per invocation, it will only ever connect to a single server, even if multiple recipients are specified. In the example above, both emails will be delivered to the MX server for example.com (since, as documented, the mail routing for the last domain in the list is used). This may or may not work, depending on the configuration of email server you are testing.


Adding Headers How do I add a header??

Use the --add-header option:

swaks --add-header "X-Test-Header: foo"

There are lots more examples in the spec, look for --header and --add-header for details and nuance about each. A quick rule of thumb though is that you want --header to overwrite a header that already exists in your test email, and you want --add-header to add a completely new header, even if that same header already exists in your test email.


Install on Mac OS X How do I install on Mac OS X?

Copy and paste or right-click, save-as works great for me. If you prefer a package manager, both MacPorts and Homebrew provide Swaks.


Install on Windows How do I install on Windows?

Swaks has been tested much less on Windows than Mac OS X or Linux (or even Solaris, Swaks' birth-OS), but it has worked when I tested it. I installed ActiveState Perl, saved the latest version of Swaks as swaks.pl, and used ppm to install perl modules. It worked fine for me, but if you are having specific issues let me know.


HTML Email How do I send HTML email?

This really depends on what you want to do. At its base, Swaks is agnostic about what it sends in its DATA section, so you can craft whatever email you want and use it as the DATA of the message using the --data option. This is the best route for testing, where you usually have a fixed set of test cases to run, or you want to run the same command many times. If you don't know what a raw email looks like, send yourself an email to a gmail account and select "Show Original". The entire text file is the format that the --data option expects (though it will probably be more complicated and have more headers than you need)

On the other hand, if you're trying to do something like use Swaks to send an email copy of a nightly HTML file, and you want the file to show up correctly in your MUA, Swaks does have a couple of helper options.

First, if you want the HTML file to be an attachment that can be openable or saveable from your MUA, you want the --attach option. For instance, the following command will attach the file report.html. --attach-type is optional, but setting it will help your MUA know what to do with the attachment:

swaks --attach-type text/html --attach report.html

Another interpretation of this question is "How do I send email which has an HTML-encoded body". This means sending an email that your MUA will display as HTML. Swaks always treats the "body" portion of a MIME email as text/plain, so you have to "cheat" and add the MIME headers yourself. The following should work:

swaks --body report.html --add-header "MIME-Version: 1.0" --add-header "Content-Type: text/html"

One potential issue with this path is that the contents of report.html won't be encoded as they would if it was processed using --attach. Whether this will be an issue or not depends on the contents of the file, the mail server(s) used to handle the mail, and the MUA used to view the mail


IPv6 Support Does Swaks support IPv6?

Yes, as of release 20120320.0! Woo!