LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   sending mails with port number 587 bash script help (https://www.linuxquestions.org/questions/linux-newbie-8/sending-mails-with-port-number-587-bash-script-help-4175537574/)

cli 03-23-2015 12:46 AM

sending mails with port number 587 bash script help
 
Hi All,
We have some shell scripts which will send emails about backup, alerts etc using mail command. Example.
Code:

echo "Test Mail" | mail -s "Test" me@mydomain.com
I guess the above command just connect port number 25 of our mail server even if we do not define any port number. Now I would like add smtp port number as 587 in all of the bash scripts. I googled for this but could not get whatever I am expecting. So expecting your kind reply to define smtp port number as 587 in all of the bash scripts.

Thanks in advance.

sag47 03-23-2015 01:11 AM

I send mail over 587. In /etc/mail/sendmail.mc I have the following lines.

Code:

define(`RELAY_MAILER_ARGS', `TCP $h 587')                                                                        define(`ESMTP_MAILER_ARGS', `TCP $h 587')
I generate /etc/mail/sendmail.cf from the mc file. However, I'm also authenticating with the SMTP server over 587. What exactly are you trying to accomplish?

cli 03-23-2015 02:05 AM

Thanks for the reply.
Where should I edit this i.e the /etc/mail/sendmail.mc is from our mail server or any local PC/Laptops where shell script will be running.
I just wanted to define smtp settings only in each shell scripts of our local servers because one of our public IP itself has been blacklisted and not able send mails to our mail server with shell scripts because of rbl enabled in our mail server. But we have made sure that our local servers can send mails with port 587 with gerrit service after changing the port number to 587 in gerrit configuration file. But not able to send mails with shell scripts which still may be trying to connect default port 25 of our mail server and getting deny error. So expecting your kind help to define the smpt port number in each bash shell scripts rather than editing the global configuration files of our local servers as few are using sendmail and few servers are using postfix.

sag47 03-23-2015 08:18 PM

Quote:

Originally Posted by cli (Post 5336231)
Where should I edit this i.e the /etc/mail/sendmail.mc is from our mail server or any local PC/Laptops where shell script will be running.

It would be on the client machine doing the sending of the email. I spent 5 minutes reading the mail man page searching for the string "port". There's an smtp string option that can be defined as...

Code:

echo "Test mail" | mail -S smtp=smtps://server:port -s "Test" me@mydomain.com
If it were me I'd want to edit the config global config files rather than a script hack. The same fix (from my first post) is not for both sendmail and postfix. Fix it for the appropriate software you have installed on the server needing to send the mail. That would be my recommendation. That and look to man pages.

thegwer 03-23-2015 09:56 PM

Even if your IPs have been blacklisted to the world you should still be able to have control over your own mailserver to White list them.
What mailserver or MTA are you running?


All times are GMT -5. The time now is 12:21 PM.