0

I am trying to run a bash to send emails from my linux server. I am using the following command:

echo "This is the message body" | mail -s "This is the subject line" -a "From: <Sender>" -a "To: <recipient>" -S smtp="smtp.gmail.com:587" -S smtp-use-starttls -S ssl-verify=ignore -S smtp-auth=login -S smtp-auth-user=$SMTP_USER -S smtp-auth-password=$SMTP_PASS <recipient_email_address>

I am receiving the error: mail: unrecognized option '-S'

As far as I read, previously mailx was used but this error shouldn't occur with mail command. can you please help me where I am going wrong?

System Info: Ubuntu 20.04.5 LTS (GNU/Linux 5.15.0-1040-azure x86_64)

mail --version >> mail (GNU Mailutils) 3.7

4
  • 2
    Please edit your question and include the output of mail --version.
    – Panki
    Commented Sep 14, 2023 at 9:08
  • ... and also mention what Linux distribution and version you are using.
    – Kusalananda
    Commented Sep 14, 2023 at 9:13
  • Does man mail show you the -S flag as an option? What does it tell you about it? Commented Sep 14, 2023 at 9:31
  • - Panki, mail --version >> mail (GNU Mailutils) 3.7 - Kusalananda, System Info: Ubuntu 20.04.5 LTS (GNU/Linux 5.15.0-1040-azure x86_64) @roaima, actually no. just checked.. any idea how to work with SMTP in that case? Commented Sep 14, 2023 at 10:57

1 Answer 1

1

The -S option to set a variable is recognised (only) by Heirloom mailx. You've got mail from GNU mailutils, which does not support this option.

If you need to set your SMTP values on the command line you will need to install Heirloom mailx. Otherwise look at getting your MTA (Mail Transport Agent) configured properly to do this all for you. For this simple case of forwarding, I would suggest you consider msmtp (configuration suggestions on the ArchWiki, which include a recipe for sending through Gmail).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .