#! /usr/bin/env groovy /** * A program that takes as input two files, a mail template and a csv file with a list of people to * send a mail to. The csv file is formatted: * * companyname,jobtitle,firstname,lastname,phonenumber,emailaddress * * and the mail template can use markers such as <%= firstname %> which will get edited with information from * the current person being mailshotted. Basically this is a standard mail merge type thing but it actually * send email rather than creates postal letters. * * @author Russel Winder * @version 0.1.1 * @date 2007-02-08 * @copyright Copyright © 2004-7 Russel Winder. All rights reserved. */ import groovy.text.SimpleTemplateEngine def transform ( toData ) { def data = toData.split ( ',' ) def definitions = [ companyname : data[0] , jobtitle : data[1] , firstname : data[2] , lastname : data[3] , phonenumber : data[4] , emailaddress : data[5] ] def engine = new SimpleTemplateEngine ( ).createTemplate ( emailTemplate ) [ definitions[ 'emailaddress' ] , engine.make ( definitions ).toString ( ) ] } def process ( toData ) { def data = transform ( toData ) [ 'sh' , '-c' , 'mail -s "' + emailSubjectLine + '" ' + data[0] + " << XXXX\n" + data[1] ].execute( ).waitFor ( ) } fromAddress = 'russel@russel.org.uk' if ( args.size ( ) != 3 ) { println( 'Usage: mailshot.py ' ) return 1 } emailSubjectLine = args[0] emailTemplate = new File ( args[1] ) .text new File ( args[2] ).eachLine { line -> process ( line ) }