1 package org.paneris.jammyjoes.mail; 2 3 import java.io.FileInputStream; 4 import java.io.IOException; 5 import java.io.InputStream; 6 7 import javax.activation.DataHandler; 8 import javax.activation.FileDataSource; 9 import javax.mail.MessagingException; 10 import javax.mail.Session; 11 import javax.mail.internet.AddressException; 12 import javax.mail.internet.MimeBodyPart; 13 14 import com.quiotix.html.parser.ParseException; 15 16 public class Newsletter extends MimeMail implements NewsletterInterface { 17 18 private String directory, name; 19 20 public Newsletter(Session session, String directory, String name) throws AddressException, MessagingException, ParseException, IOException { 21 super(session); 22 this.directory = directory; 23 this.name = name; 24 HtmlImageParser parser = new HtmlImageParser(this); 25 setContentText(parser.getText()); 26 setFrom("jenny@jammyjoes.com"); 27 setSubject("Jammy Joes Newsletter"); 28 29 } 30 31 32 public void addImage(String image, int index) throws MessagingException, IOException { 33 MimeBodyPart part = new MimeBodyPart(); 34 part.setDataHandler(new DataHandler(new FileDataSource(directory+image))); 35 part.setHeader("Content-ID","<image" + index + ">"); 36 addBodyPart(part); 37 } 38 39 public InputStream getInputStream() throws IOException { 40 return new FileInputStream(directory + name); 41 } 42 43 }