To send an email on Linux such that the recipient A receives the email, but the To: field in the email header shows B (so A sees "To: B" when they open the email), you can use the sendmail command or a command-line email client like mail or mutt with custom headers.
sendmail (most common method)You can use the following command:
bashecho "This is the email body" | sendmail -f your_email@example.com -- A@example.com
But to set the To: header to B, you need to manually construct the email headers. Here’s how you can do it:
bash( echo "To: B@example.com" echo "Subject: Your Subject Here" echo "" echo "This is the email body" ) | sendmail -f your_email@example.com A@example.com
Explanation:
To: header is set to B@example.com, so A will see "To: B" in their email client.A@example.com (passed as an argument to sendmail).mail or muttIf you have mail or mutt installed, you can use:
mail:bashecho "This is the email body" | mail -s "Your Subject Here" -r your_email@example.com -S "to=B@example.com" A@example.com
mutt:bashecho "This is the email body" | mutt -e "set from=your_email@example.com" -s "Your Subject Here" -- A@example.com -H - <<EOF To: B@example.com Subject: Your Subject Here This is the email body EOF
Note:
your_email@example.com, A@example.com, and B@example.com with the actual email addresses.