{"id":2394,"date":"2013-07-16T20:29:56","date_gmt":"2013-07-16T12:29:56","guid":{"rendered":"http:\/\/rmohan.com\/?p=2394"},"modified":"2013-07-16T20:29:56","modified_gmt":"2013-07-16T12:29:56","slug":"how-to-send-mail-from-shell-script","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=2394","title":{"rendered":"HOW TO SEND MAIL FROM SHELL SCRIPT"},"content":{"rendered":"<p>! \/bin\/bash<br \/>\n#Use: To Send Mail From Shell Script in Linux<br \/>\n#Prepared By: Online cyber Study Group<br \/>\nTO_ADDRESS=\u201dtestusr@yourdomain.com\u201d<br \/>\nFROM_ADDRESS=\u201droot@ yourdomain.com\u201d<br \/>\nSUBJECT=\u201dHOW TO SEND MAIL FROM SHELL SCRIPT\u201d<br \/>\nBODY=\u201d This is free webmail server we also called it open source mail server and we have write a bash script that have title HOW TO SEND MAIL FROM SHELL SCRIPT\u201d<br \/>\necho ${BODY MESSAGE}| mail -s ${SUBJECT } ${TO_ADDRESS} \u2014 -r ${FROM_ADDRESS}<\/p>\n<p>:wq!<\/p>\n<p>In above BASH SCRIPT I have used below four variable along with switch.<br \/>\nTO_ADDRESS = Write here user mail id which you want to send mail.<br \/>\nFROM_ADDRESS= Write sender user mail id<br \/>\nSUBJECT= Writer here subject of mail<br \/>\nBODY= Write here body message<br \/>\n-S = for Subject<br \/>\n-r = recipient address<\/p>\n<p>How to send mail in shell script with attachment<\/p>\n<p>#!\/bin\/bash<br \/>\n#Use: send mail in shell script with attachment<br \/>\n#Prepared By: Online cyber Study Group<br \/>\nTO_ADDRESS=\u201dtestusr@domain.com\u201d<br \/>\nFROM_ADDRESS=\u201dsender@yourdomain.com\u201d<br \/>\nSUBJECT=\u201dlinux mail send attachment\u201d<br \/>\nBODY_FILE=\u201dserver.dat\u201d<br \/>\nATTACHMENT_FILE=\u201dserverlogfile.txt\u201d<br \/>\nCC_LIST=\u201dtestuser2@gmail.com;testuser3@redhat.com;testuser3@onlinecyberstudy.com\u201d<br \/>\nuuencode ${ATTACHMENT_FILE} | mail -s ${SUBJECT} -c ${CC_LIST} ${TO_ADDRESS} \u2014 -r ${FROM_ADDRESS} < ${BODY_FILE}\n\n:wq!\n\nCC_LIST variable you can put here group mail id or more user id which you want to send mail. \u2013s option in mail command user to mail subject and  \u2013c option in mail command used to set more user mail in in CC ( carbon copy). Uuencode is used to send attachment file with mail command.\n<\/p>\n","protected":false},"excerpt":{"rendered":"<p>! \/bin\/bash #Use: To Send Mail From Shell Script in Linux #Prepared By: Online cyber Study Group TO_ADDRESS=\u201dtestusr@yourdomain.com\u201d FROM_ADDRESS=\u201droot@ yourdomain.com\u201d SUBJECT=\u201dHOW TO SEND MAIL FROM SHELL SCRIPT\u201d BODY=\u201d This is free webmail server we also called it open source mail server and we have write a bash script that have title HOW TO SEND MAIL [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[47],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/2394"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2394"}],"version-history":[{"count":1,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/2394\/revisions"}],"predecessor-version":[{"id":2395,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/2394\/revisions\/2395"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2394"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2394"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2394"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}