Currently the server I have has blocked emails from being sent from it due to spam issues. So I am currently looking for a way to send e-mail through the command line or shell script through an external SMTP server like gmail.

Please note that if I require other software to aid in this issue, I do not have root access on the server thus I cannot install software that requires root but I can install them locally provided that I build from source with ./configure --prefix=$HOME. The server comes with mail and that is really all that is related to email.

2 Answers 2


msmtp is a command line application that can send email over smtp. You can pipe your email into it. Keep in mind that it is not an mail user agent so you have to pipe in the whole email not just the body.


Just validate if you have mail/mailx installed. mail should be there by default.

You can use smtp details in these commands, to send email via external smtp.


mailx -S smtp=<smtp-server-address> -r <from-address> -s <subject> -v <to-address> < body.txt
  • 1
    mailx version 3.4 (running on ubuntu20, installed via mailutils apt package) does not have a -S or -v flag option. Aug 19, 2020 at 14:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.