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
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:


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.

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.

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.

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.

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 savable 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.

How do I send a BCC email?

Swaks does not have the --bcc option so many people seem to be asking for lately. It may never get it, as it's not really true to Swaks' core functionality as a transaction tester, versus an MUA. That said, for those who really need this functionality, here's how to do it.

First, the reason you don't need a special option to do this:

  1. The envelope-recipients of an email and the contents of the To: and Cc: headers in an email are only related by convention.
  2. By default, Swaks places the envelope-recipients (specified by --to) into the To: header.
  3. However, as the user of Swaks, you have complete freedom to set the --to option and the To: header independently.
  4. Therefore, to "BCC" someone is the same as specifying them in the --to recipients, but specifying a To: header that does not include them.

So, to send a message to aa@example.com and bb@example.com, but only include aa@example.com in the To: header (or, put another way, to BCC bb@example.com), the following would work:

swaks --to aa@example.com,bb@example.com --header "To: aa@example.com"
Does Swaks support IPv6?

Yes, as of release 20120320.0! Woo!