Nov 10, 2018

How to send mail from command line with external smtp server on Linux

The default mail command on the Linux terminal, uses the local SMTP server (MTA) on port 25 to transmit emails. However sometimes you may want to specify an external SMTP server to use for sending mails. You can use mailx command:

$ echo "This is the message body" | mailx -v -r "" -s "This is the subject" -S smtp="" -S smtp-use-starttls -S smtp-auth=login -S smtp-auth-user="" -S smtp-auth-password="password" -S ssl-verify=ignore