Can't set From using mail command in bash

133 Views Asked by At

I am at my wits end....

All I want to do is set the From using a command line mail in a script.

I have tried mutt, mail, mailx...

Here is on command I tried:

echo "Once again" | mail -s "Maybe this time" -A file.csv [email protected] -r 'John <[email protected]>' -a From:John\<[email protected]\>

And another:

mutt -e "set [email protected]"...

And another:

mutt -e "set [email protected]" -e "set realname=John"

My /etc/mailname has the name I want too. I also tried configuring a muttrc file and that doesn't work

And another try:

mailx -r "[email protected]" -a "From:[email protected]" -s "Subject" -A "/opt/file.csv" "[email protected]" <<< Some Text

Any ideas I can try?

1

There are 1 best solutions below

5
On

I assume that you have configured [email protected] in an extra configuration file (~/.mutt/accounts/john) which you usually source as soon as you start using it in mutt. Simply load that configuration.

echo "mail body" | mutt -e "source ~/.mutt/accounts/john" -e "set content_type=text/plain" -s "subject" -- [email protected]

An account specific configuration file may look like this (msmtp is used in this case to send mails):

set sendmail        = "/usr/bin/msmtp -a Mailbox"
set realname        = "John"
set from            = "[email protected]"
set mbox_type       = Maildir
set folder          = "/home/john/.mails"
set spoolfile       = "+Mailbox/INBOX"
set record          = "+Mailbox/Sent"
set postponed       = "+Mailbox/Drafts"