user127192 user127192 - 1 month ago 8
Bash Question

Send e-mail with custom From: and Cc:

I am trying to automate my email by using this command on unix VI:

echo 'Message body goes here' | mail -s 'subject line goes here' email@provider.com


However, I would like to add a "CC" and use a different email address showing when I send the email to the recipient.

Answer

mailx is usually link with mail.

Try passing the options to sendmail by putting double-dash at the end and then specifying -f (from) or -r (return):

mailx ....    -- -r returnname@domain.com

mailx ....    -- -f returnname@domain.com

You could also try "-a" option as mentioned here

mailx -a 'From:name@your-domain.com'  ...

If you want to try the sendmail:

sendmail -t <<EOF
To: toname@domain.com
Subject: Hi
From: fromname@domain.com
Reply-To: replyname@domain.com
Hello
EOF