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 the command line. To install swaks do the following:

# aptitude install -y swaks

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

# swaks --to --from "" --header "Subject: Test mail" --body "This is a test mail" --attach-type application/zip --attach --server --port 587 --timeout 40s --auth LOGIN --auth-user "" --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
Leave a Reply 0

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