Question

I have created one shell script which performs some database query and created a cron tab to execute that shell script. I am generating log for this task to check whether script is executed successfully or not.
Now I want to send this log file to developer using smtp ?
How can I configure smtp in shell script ?
Thanks in advance.

Was it helpful?

Solution

You can use SendEmail script (https://github.com/mogaal/sendemail)

It is a very good command line smtp client. YoU can run it from crontab. Example usage:

sendEmail -f fromAddr@example.com -t toAddr@example.com -s smtp.server.com -u theSubject -m the Message -a fileToAttach

Description from official site:

SendEmail is a lightweight, command line SMTP email client. If you have the need to send email from a command line, this free program is perfect: simple to use and feature rich. It was designed to be used in bash scripts, batch files, Perl programs and web sites, but is quite adaptable and will likely meet your requirements. SendEmail is written in Perl and is unique in that it requires NO MODULES. It has an intuitive and flexible set of command-line options, making it very easy to learn and use.

SendEmail is licensed under the GNU GPL, either version 2 of the License or (at your option) any later version.

[Supported Platforms: Linux, BSD, OS X, Windows 98, Windows NT, Windows 2000, & Windows XP]

OTHER TIPS

You can use the following command to send an email from the command line, or from a shell script:

/usr/sbin/sendmail recipient@domain.tld < /path/to/message/to/send.txt
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top