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 someone@tld.com --from "me@sefnet.local" --header "Subject: Test mail" --body "This is a test mail" --attach-type application/zip --attach file.zip --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
Any suggestions how to make this work with a cron job? Thank you.