{"id":120,"date":"2012-09-27T09:01:18","date_gmt":"2012-09-27T06:01:18","guid":{"rendered":"http:\/\/www.suuronen.eu\/blog\/?p=120"},"modified":"2013-01-28T10:15:37","modified_gmt":"2013-01-28T07:15:37","slug":"sending-emails-with-groovy-from-xml-file","status":"publish","type":"post","link":"https:\/\/suuronen.eu\/blog\/sending-emails-with-groovy-from-xml-file\/","title":{"rendered":"Sending emails with groovy from xml file"},"content":{"rendered":"<p>If you have an xml file containing people&#8217;s emails like:<\/p>\n<pre lang=\"xml\" line=\"1\" escaped=\"false\"><!--?xml version='1.0' encoding='UTF-8'?-->\r\n\r\n    Mikko Mallikas\r\n    mikko@null\r\n\r\n    Minni Muodikas\r\n    minni@null<\/pre>\n<p>You can easily send simple email messages to them with Groovy:<\/p>\n<pre lang=\"groovy\" line=\"1\">def doc = new XmlParser().parse(\"\/tmp\/emails.xml\")\r\n\r\ndoc.person.email.each {\r\n  doCommand(\"echo \\\"Body text here \\\" | mail -s \\\"Subject here\\\" \" + it.text())\r\n}\r\n\r\ndef doCommand(command) {\r\n  String[] cmd = [\"\/bin\/sh\", \"-c\", command]\r\n  def proc = Runtime.getRuntime().exec(cmd)\r\n  proc.waitFor()\r\n}<\/pre>\n<p>Note that this works only on linux, due the mail program used not found in Windows OS.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you have an xml file containing people&#8217;s emails like: Mikko Mallikas mikko@null Minni Muodikas minni@null You can easily send simple email messages to them with Groovy: def doc = new XmlParser().parse(&#8220;\/tmp\/emails.xml&#8221;) doc.person.email.each { doCommand(&#8220;echo \\&#8221;Body text here \\&#8221; | &hellip; <a href=\"https:\/\/suuronen.eu\/blog\/sending-emails-with-groovy-from-xml-file\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[12],"class_list":["post-120","post","type-post","status-publish","format-standard","hentry","category-coding","tag-groovy"],"_links":{"self":[{"href":"https:\/\/suuronen.eu\/blog\/wp-json\/wp\/v2\/posts\/120","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/suuronen.eu\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/suuronen.eu\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/suuronen.eu\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/suuronen.eu\/blog\/wp-json\/wp\/v2\/comments?post=120"}],"version-history":[{"count":17,"href":"https:\/\/suuronen.eu\/blog\/wp-json\/wp\/v2\/posts\/120\/revisions"}],"predecessor-version":[{"id":205,"href":"https:\/\/suuronen.eu\/blog\/wp-json\/wp\/v2\/posts\/120\/revisions\/205"}],"wp:attachment":[{"href":"https:\/\/suuronen.eu\/blog\/wp-json\/wp\/v2\/media?parent=120"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/suuronen.eu\/blog\/wp-json\/wp\/v2\/categories?post=120"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/suuronen.eu\/blog\/wp-json\/wp\/v2\/tags?post=120"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}