How to send mail from command line using swaks

Swaks (Swiss Army Knife for SMTP) is a simple, yet powerful command line tool that can be used for SMTP server testing as well as to send mail directly from command line. To install swaks do the following:

# aptitude install -y swaks

To send a simple mail from command line do the following:

# swaks --to --from "me@sefnet.local" --header "Subject: Test mail" --body "This is a test mail" --attach-type application/zip --attach --server smtp.sefnet.local --port 587 --timeout 40s --auth LOGIN --auth-user "me@sefnet.local" --auth-password "MyPassword" -tls

Now lets break this down:

–from – address you want to appear as from
–header – header part including Subject
–body – Text you want to appear in the mail boxy. You can create a text file and use that instead (–body file.txt)
–attach-type – attachment mime type, can be repeated as needed
–attach – mail attachment, can be repeated as needed
–server – SMTP server you want to use to send mail
–port – SMTP server port, I use 587 (submission)
–timeout – timeout in seconds/minutes is there is delay in SMTP communication as in case of fight against spam
–auth – authentication type
–auth-user – username used for SMTP authentication
–auth-password – password used for SMTP authentication
–tls – tells swaks to STATTLS

For all other options make sure to

# man swaks

5 Replies to “How to send mail from command line using swaks”

  1. Hi,

    Do you know how to use swaks when the smtp account password contents the minus character like -Areuhhh10- ?

    Thanks a lot !


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.