FileDocCategorySizeDatePackage
BatchMailer.javaAPI DocExample1923Sun Feb 08 21:33:48 GMT 2004None

BatchMailer

public class BatchMailer extends Object
Command-line batch mailer

Fields Summary
protected String
messageBody
The message
protected String
subject
The subject
protected ArrayList
custList
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] args)

		if (args.length != 3) {
			System.err.println("Usage: BatchMail subj template custlist");
			System.exit(1);
		}
		BatchMailer b = new BatchMailer();
		String subj = args[0];
		String template = args[1];
		String listfile = args[2];
		b.readTemplate(template);
		b.setSubject(subj);
		b.readCustList(listfile);
		b.sendMails();
	
public voidreadCustList(java.lang.String fileName)
Read the customer list. Format: one customer email per line.


	           	  
	      
		BufferedReader is = new BufferedReader(new FileReader(fileName));
		String line;
		while ((line = is.readLine()) != null) {
			custList.add(line);
		}
		is.close();
	
public voidreadTemplate(java.lang.String fileName)
Read the template file.


	    	  
	      
		messageBody = null;
		BufferedReader is = new BufferedReader(new FileReader(fileName));
		String line;
		StringBuffer bs = new StringBuffer();
		while ((line = is.readLine()) != null) {
			bs.append(line).append("\n");
		}
		messageBody = bs.toString();
		is.close();
	
public voidsendMails()

		Iterator it = custList.iterator();
		while (it.hasNext()) {
			String customer = (String)it.next();
			try {
				// This should be a bit more flexible :-(
				Mailer.send("mailhost", 
					customer, "http://www.darwinsys.com/", subject, messageBody);
				System.out.println(customer + " HANDOFF OK");
			} catch (MessagingException e) {
				System.out.println(customer + " failed: " + e.toString());
			}
		}
	
public voidsetSubject(java.lang.String s)

		subject = s;