Does anyone know how to change the from user when sending email using the mail command? I have looked through the man page and can not see how to do this.
We are running Redhat Linux 5.
You can specify any extra header you may need with -a
$mail -s "Some random subject" -a "From: some#mail.tld" to#mail.tld
http://www.mindspill.org/962 seems to have a solution.
Essentially:
echo "This is the main body of the mail" | mail -s "Subject of the Email" recipent_address#example.com -- -f from_user#example.com
mail -r from#from.from -R from#from.com
-r = from-addr
-R = reply-to addr
The author has indicated his version of mail doesn't support this flag. But if you have a version that does this works fine.
When sending over SMTP, the mail man page advises to set the from variable, in this way (Tested on CentOS 6):
mail -s Subject -S from=sender#example.com recipient#example.com
You could also attach a file using the -a option:
mail -s Subject -S from=sender#example.com -a path_to_attachement recipient#example.com
None of these worked for me (Ubuntu 12.04) but finally with trial & error I got:
echo 'my message blabla\nSecond line (optional of course)' |
mail -s "Your message title"
-r 'Your full name<yourSenderAdress#yourDomain.abc>'
-Sreplyto="yourReplyAdressIfDifferent#domain.abc"
destinatorEmail#destDomain.abc[,otherDestinator#otherDomain.abc]
(all in one line, there is no space in "-Sreplyto")
I got this mail command from:
apt-get install mailutils
You can append sendmail options to the end of the mail command by first adding --. -f is the command on sendmail to set the from address. So you can do this:
mail recipient#foo.com -- -f sender#bar.com
None of the above worked for me. And it took me long to figure it out, hopefully this helps the next guy.
I'm using Ubuntu 12.04 LTS with mailutils v2.1.
I found this solutions somewhere on the net, don't know where, can't find it again:
-aFrom:Servername-Server#mydomain.com
Full Command used:
cat /root/Reports/ServerName-Report-$DATE.txt | mail -s "Server-Name-Report-$DATE" myemailadress#mydomain.com -aFrom:Servername-Server#mydomain.com
Here's a solution.
The second easiest solution after -r (which is to specify a From: header and separate it from the body by a newline like this
$mail -s "Subject" destination#example.com
From: Joel <joel#example.com>
Hi!
.
works in only a few mail versions, don't know what version redhat carries).
PS: Most versions of mail suck!
on CentOs5: -r from#me.omg
echo "This is the main body of the mail" | mail -s "Subject of the Email" recipent_address#example.com -- -f from_user#example.com -F "Elvis Presley"
or
echo "This is the main body of the mail" | mail -s "Subject of the Email" recipent_address#example.com -aFrom:"Elvis Presley<from_user#example.com>"
Most people need to change two values when trying to correctly forge the from address on an email. First is the from address and the second is the orig-to address. Many of the solutions offered online only change one of these values.
If as root, I try a simple mail command to send myself an email it might look like this.
echo "test" | mail -s "a test" me#noone.com
And the associated logs:
Feb 6 09:02:51 myserver postfix/qmgr[28875]: B10322269D: from=<root#myserver.com>, size=437, nrcpt=1 (queue active)
Feb 6 09:02:52 myserver postfix/smtp[19848]: B10322269D: to=<me#noone.com>, relay=myMTA[x.x.x.x]:25, delay=0.34, delays=0.1/0/0.11/0.13, dsn=2.0.0, status=sent (250 Ok 0000014b5f678593-a0e399ef-a801-4655-ad6b-19864a220f38-000000)
Trying to change the from address with --
echo "test" | mail -s "a test" me#noone.com -- dude#thisguy.com
This changes the orig-to value but not the from value:
Feb 6 09:09:09 myserver postfix/qmgr[28875]: 6BD362269D: from=<root#myserver.com>, size=474, nrcpt=2 (queue active)
Feb 6 09:09:09 myserver postfix/smtp[20505]: 6BD362269D: to=<me#noone>, orig_to=<dude#thisguy.com>, relay=myMTA[x.x.x.x]:25, delay=0.31, delays=0.06/0/0.09/0.15, dsn=2.0.0, status=sent (250 Ok 0000014b5f6d48e2-a98b70be-fb02-44e0-8eb3-e4f5b1820265-000000)
Next trying it with a -r and a -- to adjust the from and orig-to.
echo "test" | mail -s "a test" -r dude#comeguy.com me#noone.com -- dude#someguy.com
And the logs:
Feb 6 09:17:11 myserver postfix/qmgr[28875]: E3B972264C: from=<dude#someguy.com>, size=459, nrcpt=2 (queue active)
Feb 6 09:17:11 myserver postfix/smtp[21559]: E3B972264C: to=<me#noone.com>, orig_to=<dude#someguy.com>, relay=myMTA[x.x.x.x]:25, delay=1.1, delays=0.56/0.24/0.11/0.17, dsn=2.0.0, status=sent (250 Ok 0000014b5f74a2c0-c06709f0-4e8d-4d7e-9abf-dbcea2bee2ea-000000)
This is how it's working for me. Hope this helps someone.
This works on Centos7
echo "This is the main body of the mail" | mail -s "Subject of the Email" -r seneder_address#whatever.com recipent_address#example.com
Here's an answer from 2018, on Debian 9 stretch.
Note the -e for echo to allow newline characters, and -r for mailx to show a name along with an outgoing email address:
$ echo -e "testing email via yourisp.com from command line\n\nsent on: $(date)" | mailx -r "Foghorn Leghorn <sender#yourisp.com>" -s "test cli email $(date)" -- recipient#somedomain.com
Hope this helps!
For CentOS here is the working command :
mail -s Subject -S from=sender#example.com recipient#example.com
Thanks to all example providers, some worked for some not.
Below is another simple example format that worked for me.
echo "Sample body" | mail -s "Test email" from=sender-addrs#example.com recepient-addres#example.com
Related
I'm trying to do a sh script to netcat an IP and to send an email when a the port is not answering.
So far I have this but altought the script is working and the output file in filled in, but I receive the mail is empty. I debug it by writing something with vi in the output file and I do get the email with what I've written.
Here's the script:
netcat -z -v -w x.x.x.x 23 > /path/resultt.txt 2>&1
if grep -q "timed out" /path/resultt.txt ;
then
ssmtp email#gmail.com < /path/resultt.txt
else
echo
fi
I think it has something to do with doing 2>&1
Your use of 2>&1 or "send stderr to the same place as stdout" should not be a problem. In cases where the last argument is a number, I like to make sure my redirects have the fd number on them. But, yours does work without it.
I'm using a public telnet based service for this demo. It should work for anyone, but as with all things free, it may not be around forever.
$ nc telnetmyip.com 23 > /tmp/out 2>&1
$ cat /tmp/out
{
"comment": "## Your IP Address is 96.67.120.126 (59742) ##",
"family": "ipv4",
"ip": "96.67.120.126",
"port": "59742",
"protocol": "telnet",
"version": "v1.1.0",
"website": "https://github.com/packetsar/checkmyip"
}
So, that is working exactly as intended.
Now, you say "but I receive the mail is empty". According to your code, an email is only sent if "timed out" is present in the file. So, the only way for an empty email to be sent is if you are not giving the correct file to ssmtp the correct way.
You may want to consider doing it like the example at https://wiki.archlinux.org/index.php/SSMTP#Sending_email
# only do this once
$ cat > header.txt <<'EOF'
To:email#gmail.com
From:youraccount#gmail.com
Subject: telnet resulted in a timeout
Hello, admin. I hope this doesn't ruin your day.
The command `netcat -z -v -w x.x.x.x 23 > /path/resultt.txt` resulted in this:
EOF
$ cat header.txt /path/resultt.txt | sendmail -t
I hope that helps. In closing I'll repeat: The only way for an empty email to be sent is if you are not giving the correct file to ssmtp the correct way. (Assuming that you have manually confirmed that ssmtp works in this environment.)
I am using linux mail command to send an automated email to a bunch of people once per week.
I want each one of the recipients to be BCC'ed.
I am trying this command:
mail -v -s "Email Subject" -b george#gmail.com, maria#email.com, gina#correo.com, asher#texting.com -- -f jpatino#azucarcolombia.com < /pathTo/dir/emailText.txt
But get this error:
You must specify direct recipients with -s, -c, or -b.
you need to put them all in a single argument by quoting it.
mail -v -s "Email Subject" -b 'george#gmail.com, maria#email.com, gina#correo.com, asher#texting.com' -- -f jpatino#azucarcolombia.com < /pathTo/dir/emailText.txt
It seems there are multiple versions of the mail command.
mail (GNU Mailutils) 3.7 has an append option to add headers and values directly without piping them in. Just add the headers you need there, e.g. bcc:
echo "Just testing my sendmail" | mail -s "Sendmail test" test#to.com --append=Bcc:test#bcc.com,other#bcc.com
How to send mail through BCC in UNIX
Are there any command line options/flags/ways to compose a message with mutt and skip the interface entirely? For example, when I run something like
mutt -i ~/output.txt -s 'Test results' name#domain.com
I don't want 3 editor windows and a compose menu (where I have to enter 'y' to send) to come up that I have to manually get through before sending the message. This is to be run in a cron-job so it should be fully automated.
this seems to work with my version of mutt, but I don't know if the feature is universally available:
echo "" | mutt -s "my subject" -i <(echo bla) -a file.txt -- name#domain.com
I have a crontab which is supposed to send an email, but it doesn't.
echo " ok backup " > /home/nuvoshift01/zDB-backup-start.txt
mysqldump --opt --user=q --password=xyz --host=localhost giladparking > /home/nuvoshift01/GPmonthly-DBdump.sql
mutt me#gmail.com -s "MySQL BackUp" -a /home/nuvoshift01/GPmonthly-DBdump.sql < /home/nuvoshift01/zDB-backup-start.txt > /home/nuvoshift01/whatHappened.txt
touch /home/nuvoshift01/zDB-bacup-end.txt
(1) the first line does touch the file as coded
(2) the back up file is created
(3) the mutt mail does not send
(4) the 4th line does touch the file as coded
if I issue the mutt command from the command the email IS sent with the attachment
my puzzle/question is: why doesn't the email get sent by the crontab?
OK, today I provide the solution to my own problem. I determined to send the email with mutt I needed to create a properly configured .muttrc file AND explicitly describe the path in the cron task.
my .muttrc file looks like this :
set from = "anyaddress#anydomain.com"
set hostname = hostname.com
set envelope_from = yes
the mutt command needs to look like this:
mutt -F /home/user/.muttrc -s "SUBJECT" any#address.com -a /home/user/attachedfile.txt < /home/user/bodyofmessage.txt
It turns out the message will likely end up in the spam folder of the recipient.
A special thank you for Major Hayden at Rack Space for his assistance behind the scenes.
I am using mail command to send an email. It works fine.
echo "Ignore this email" | mail -s "Test Data" DL-host-PD-WAS-TT_Emp#corp.host.com
But the only confusion I have is, in my email I didn't get any subject and it always show as (no subject) in my email as I am also specifying subject option in the above command as -s but it is not working I guess somehow.
I am running SunOS.
bash-3.00$ uname -a
SunOS lvsaishdc3in0001 5.10 Generic_142901-02 i86pc i386 i86pc
And also I am not seeing To: list in my email. How can I make this thing works?
On all Solaris systems, you should not use "mail", you should use "mailx".
Try using mailx. http://www.cisl.ucar.edu/tcg/consweb/Solaris/mail.html
Modify your command like this-
echo "Ignore this email" | mailx -s "Test Data" DL-host-PD-WAS-TT_Emp#corp.host.com