You are here

Sending a message from the command line in Ubuntu

Submitted by Druss on Fri, 2021-09-24 22:05

This is how you can send a message from the commandline using the mailx (mailutils) package.

$ mailx -s "Re: My mail subject" -r "<foo-sender@example.com>" bar-recipient@example.com < contents.txt

Note, however, that I was unable to specify the sender's name. -r "Foo<foo-sender@example.com>" and -r "<foo-sender@example.com> (Foo)" did not work (and neither did the versions with the email addresses with the <> removed. What was sent instead was the username of the commandline account.

My workaround was to create a brand new user account on the system using sudo useradd -m myusername  -c "My Name" and switching into that account while mailing out.

Hope this helps.