Linux shell emailing - set sender address using "mail" command - linux

I am using the "mail" command in Linux shell to send an email when programmatically prompted to do so. I am using
mail -s 'subject' recipient#theirhost.com <<< 'Email body'
to send it at present, but this does not include a sender address. Instead, the system uses the account name as the sender address. I've seen the claim that "-aFrom:myname#myhost.com" should work, but -a is being interpreted as an attachment attempt, not a header change. This results in the error: "From:Mynamemyname#myhost.com: No such file or directory". I've also seen a claim that this works:
-r "from#fromserver.com"
But the OS doesn't even know what that means, in my case.
Is there a way to make this work without additional software? I don't need a from name, but a from address would be very helpful.
Note: let's consider ssmtp, mutt, and other such add-on software unavailable. Attempting to install and use such software would be problematic.
Thank you!
Edit 1: I'm not certain how to check what version of "mail" I have. With some difficulty, I got it to spit out the usage, which is as follows.
-T FILE -u USER -h hops -r address -s SUBJECT -a FILE -q FILE -f FILE -A ACCOUNT -b USERS -c USERS -S OPTION users

Never mind, I got it. "-r" can actually work.
I successfully used:
echo "This is the message body" | mail -s "This is the Subject" -r "FromName<fromAddress#example.com>" recipientName#example.com
It looks like karakfa was onto something also, as I do have mailx available to me also, but it looks like I won't be needing that for this use case.
Thank you!

Related

unable to send mail using Mutt

Recently we have migrated Unix OS to new flavor. Since then we couldn't able to send mails. I think we are missing some configuration, Could someone help in resolving the issue.
Command: echo "" | mutt -s "subject" -i /tmp/test.txt -a /tmp/test.txt xxx#gmail.com
Error: Can't stat xxx#gmail.com: No such file or directory
xxx#gmail.com: unable to attach file.
Current OS: Oracle Linux Server release 7.1
Mutt 1.5.21 (2010-09-15)
Please let me know what would be the issue.
Take a look at the man page. It states, that -a takes a list of arguments, which need to be terminated by --.

Linux mail command to bcc multiple addresses?

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

send mail from linux terminal in one line [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 6 years ago.
Improve this question
I know there is the command mail in linux to send emails via command line. How can I send an simple email with one line from the terminal though?
For example:
mail user#gmail.com [subject] [body]
And have the email sent without any confirmation or prompts to the user?
The reason is, I want to send a brief message via email to myself when a specific event happens in a java program. The idea is that I will use Runtime.getRuntime()… etc. to send the mail command from my java program.
I used cron to do something similar in the past, but the current implementation doesn't use cron, so I need to try this out instead.
mail can represent quite a couple of programs on a linux system. What you want behind it is either sendmail or postfix. I recommend the latter.
You can install it via your favorite package manager. Then you have to configure it, and once you have done that, you can send email like this:
echo "My message" | mail -s subject user#gmail.com
See the manual for more information.
As far as configuring postfix goes, there's plenty of articles on the internet on how to do it.
Unless you're on a public server with a registered domain, you generally want to forward the email to a SMTP server that you can send email from.
For gmail, for example, follow
http://rtcamp.com/tutorials/linux/ubuntu-postfix-gmail-smtp/
or any other similar tutorial.
echo "Subject: test" | /usr/sbin/sendmail user#domain.com
This enables you to do it within one command line without having to echo a text file. This answer builds on top of #mti2935's answer. So credit goes there.
You can use an echo with a pipe to avoid prompts or confirmation.
echo "This is the body" | mail -s "This is the subject" user#gmail.com
For Ubuntu users: First You need to install mailutils
sudo apt-get install mailutils
Setup an email server, if you are using gmail or smtp. follow this link. then use this command to send email.
echo "this is a test mail" | mail -s "Subject of mail" username#domain.com
In case you are using gmail and still you are getting some authentication error then you need to change setting of gmail:
Turn on Access for less secure apps from here
You can also use sendmail:
/usr/sbin/sendmail user#domain.com < /file/to/send
You can install the mail package in Ubuntu with below command.
For Ubuntu -:
$ sudo apt-get install -y mailutils
For CentOs-:
$ sudo yum install -y mailx
Test Mail command-:
$ echo "Mail test" | mail -s "Subject" youremail#domain.com
Sending Simple Mail:
$ mail -s "test message from centos" recipient#example.com
hello from centos linux command line
Ctrl+D to finish

crontab mutt email fails to be sent

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.

Subject Name not showing in my email using mail command

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

Resources