Re: How to send mail by commandline
To send mails from command-line the mail command alone is not enough. You also need a properly configured mail transfer agent (MTA). It doesn't have to be a full-fledged MTA like sendmail, postfix, or exim4. If all you want is getting mails off your system then you can use a simple relay-only MTA like ssmtp, esmtp, msmtp-mta, or nullmailer.
Alternatively, use something like sendEmail or mentioned above mailsend instead of mail/mailx.
Re: How to send mail by commandline
Sorry, you are correct, I need to have the following command line to work properly- echo "mail body........" | mail -s "mail subject...." username@domain.com if required by destination mail server we can add the -aFrom:senderuser@localdomain too. the mail should go out of our local domain through ISP connection to any external mail address.
Re: How to send mail by commandline
Quote:
Originally Posted by
dvks
Sorry, you are correct, I need to have the following command line to work properly- echo "mail body........" | mail -s "mail subject...."
username@domain.com if required by destination mail server we can add the -aFrom:senderuser@localdomain too. the mail should go out of our local domain through ISP connection to any external mail address.
And why don't you use mailsend for that?
No, let me rephrase that: what is your functional requirement?
If your functional requirement is: "I want to send a mail from my system, with a certain from-address, with a certain (external) to-address, via a defined SMTP server, and possibly with an attachment" ... I would advice mailsend.
If your functional requirement is "I want to use the 'mail' command line fuction", my question would be: Why?
Re: How to send mail by commandline
sanderj & schragge thanks for your time
1. I need the "mail" to work since I need to resolve the send mail problem on a system that I am not too much familiar with and I know that they are using the "mail" command in their scripts, I prefer to fix mail instead of searching and changing the scripts.
2. I understand from achragge that actually I will solve the problem by setting any MTA that can send mail, this is good.
a. Can you recommend a "simple" MTA that can be used to send mail through ISP connection
b. which of - ssmtp, esmtp, msmtp-mta, or nullmailer, or other should I choose, better one with good setting instructions.
c. Any detailed instructions on setting of the MTA for sending out mail through ISP connection?
Thanks
Re: How to send mail by commandline
Quote:
Originally Posted by
dvks
sanderj & schragge thanks for your time
1. I need the "mail" to work since I need to resolve the send mail problem on a system that I am not too much familiar with and I know that they are using the "mail" command in their scripts, I prefer to fix mail instead of searching and changing the scripts.
2. I understand from achragge that actually I will solve the problem by setting any MTA that can send mail, this is good.
a. Can you recommend a "simple" MTA that can be used to send mail through ISP connection
b. which of - ssmtp, esmtp, msmtp-mta, or nullmailer, or other should I choose, better one with good setting instructions.
c. Any detailed instructions on setting of the MTA for sending out mail through ISP connection?
Thanks
I believe recommendations have already been given. Often there is wizard during the "sudo apt-get install". You should choose "smart host" and then select the local (or ISP) relay host.
It was in the 90's that I did setup sendmail configs ... I'm so glad that I don't do that anymore ... ;)
Re: How to send mail by commandline
I will try to set MTA and hope everything will start working.
Appreciate you help
Thanks
Re: How to send mail by commandline
Well, there are lots of online sources on how to configure mentioned MTAs. E.g.
Re: How to send mail by commandline
schragge,
Thanks for the information
Re: How to send mail by commandline
OK ... I didn't want to do this, but I did:
Setup Postfix:
Code:
sudo apt-get install postfix
Fill out the wizard:
- choose "Internet with smart host"
- fill out FQDN of your host
- fill out your (ISP's) smart host
Ready
Set hostname with a FQDN name:
Code:
sudo nano /etc/hostname
Fill out a resolvable FQDN of your host. I choose a name of remote system / domain I own.
Save and exit
Reboot your system
Install and use 'mail':
Code:
sudo apt-get install mailutils
echo Hello | mail -s "this is a test" yourmailaddress@gmail.com
... and ... bingo! It works for me
HTH
Re: How to send mail by commandline
Sanderj,
Thanks for doing the extra steps and checking the setup
I will follow your instructions
Your feedback is very useful to me
Thanks again