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 | 0 | super(session); |
22 | 0 | this.directory = directory; |
23 | 0 | this.name = name; |
24 | 0 | HtmlImageParser parser = new HtmlImageParser(this); |
25 | 0 | setContentText(parser.getText()); |
26 | 0 | setFrom("jenny@jammyjoes.com"); |
27 | 0 | setSubject("Jammy Joes Newsletter"); |
28 | |
|
29 | 0 | } |
30 | |
|
31 | |
|
32 | |
public void addImage(String image, int index) throws MessagingException, IOException { |
33 | 0 | MimeBodyPart part = new MimeBodyPart(); |
34 | 0 | part.setDataHandler(new DataHandler(new FileDataSource(directory+image))); |
35 | 0 | part.setHeader("Content-ID","<image" + index + ">"); |
36 | 0 | addBodyPart(part); |
37 | 0 | } |
38 | |
|
39 | |
public InputStream getInputStream() throws IOException { |
40 | 0 | return new FileInputStream(directory + name); |
41 | |
} |
42 | |
|
43 | |
} |