Archive

Posts Tagged ‘bash’

Sync Mail configuration in my project

January 22, 2016 Leave a comment

Environment Setup:

OS: Ubuntu 14.04

Send Mail Client: Download from the below URL

http://caspian.dotconf.net/menu/Software/SendEmail/

1.Extract and copy the send mail client to /usr folder

In Terminal:# cp -a sendEmail-v1.XX/sendEmail /usr/local/bin

2. Make the file as executable

chmod +x /usr/local/bin/sendEmail

3. Test by executing the below command in terminal

In Terminal:# sendEmail or /usr/local/bin/sendEmail

4. Create a view in production database

CREATE OR REPLACE VIEW synchtest AS
SELECT count(1) AS syncstatus
FROM sym_outgoing_batch
WHERE sym_outgoing_batch.status <> ALL (ARRAY[‘OK’::bpchar, ‘NE’::bpchar]);

5. Create bash script file to automate sync mail.

the conditions as follows
If  sync count is equal to zero, No need to send email.
If  sync count is not equal to zero, then email will be send to customer and support desk.

SyncCheck.sh
————————————————————————————————————————————-
rm -rf /home/preprod/syncmail/syncconf.txt
PGPASSWORD=123456
export PGPASSWORD
/opt/PostgreSQL/9.0/bin/psql -h serverip -U adempiere -d databasename -o /home/preprod/syncmail/syncconf.txt -c ‘select * from synchtest’;
PGPASSWORD=
export PGPASSWORD
#Sync Condition check
syncount=`sed -n ‘3p’ /home/preprod/syncmail/syncconf.txt`;
echo $syncount;
if [ $syncount -ne 0 ]; then
/home/preprod/syncmail/SyncMailNE.sh
else
exit 1
fi

——————————————————————————————————————————————-

SyncMailNE.sh – Copy & paste the below script and make it as executable.

——————————————————————————————————————————————-
/usr/local/bin/sendEmail -f fromaddress@mail.com \

-t toaddress@mail.com \

-s smtp.gmail.com:587 \

-o tls=yes \

-xu fromaddress@gmail.com \

-xp fromaddress password \

-u “subject” \

-m “body text message” \

-a /attachment/location/syncconf.txt

——————————————————————————————————————————————-

6. Create a cronjob

In Terminal:# sudo crontab -e

30 10 * * * /home/pothys/syncmail/SyncCheck.sh >> /var/log/synchmaillog 2>&1

For Gmail, install the following plugin in ubuntu

In Terminal:# sudo apt-get install libnet-ssleay-perl libio-socket-ssl-perl

Also Enable less secure access for gmail account use the below given link for instruction

https://support.google.com/accounts/answer/6010255

Note: For other domain email id’s you can use directly

Share your thoughts!

 

 

Categories: Linux Tags: , , ,