MontyPython MontyPython - 9 months ago 36
SQL Question

Sending automated e-mails with SQL output in Linux

I am fairly new to the Linux environment and I am loving it. Command-line rocks! I'm stuck with a scenario wherein I need to send comma separated files via mail at specific times of the day. The comma-separated file should be created when a query runs on the MySQL database that I am using. So, essentially, I need a cron which detects the presence of a file in some folder and fetches that as an attachment to the mail, sends the mail, and moves the file to another folder called 'done' or 'sent'. I have installed crontab. I have the queries ready.

I tried this - Automated e-mail based on SQL results, but is doesn't solve my purpose.


Found out a solution for this. We can use the mailsend utility for this.

/usr/local/bin/mailsend -auth -port 587 -domain $HOSTNAME -to $MAILINGLIST
 -sub "So-and-so-Report for $mydate" -smtp -user
 $MAILUSER -pass $MAILPASSWORD -f $FROM@$FROM -M "Report Sent! -  $mydate