1 3 package jodd.mail; 4 5 import java.util.ArrayList ; 6 import java.util.Date ; 7 import java.util.HashMap ; 8 import java.util.Map ; 9 10 import javax.activation.DataHandler ; 11 import javax.activation.FileDataSource ; 12 import javax.mail.MessagingException ; 13 import javax.mail.internet.MimeBodyPart ; 14 15 21 public class Email { 22 23 25 private String from; 26 31 public void setFrom(String from) { 32 this.from = from; 33 } 34 39 public String getFrom() { 40 return from; 41 } 42 43 44 45 private String [] to; 46 51 public void setTo(String to) { 52 this.to = new String [1]; 53 this.to[0] = to; 54 } 55 60 public void setTo(String [] to) { 61 this.to = to; 62 } 63 68 public String [] getTo() { 69 return to; 70 } 71 72 73 private String [] cc; 74 79 public void setCc(String cc) { 80 this.cc = new String [1]; 81 this.cc[0] = cc; 82 } 83 88 public void setCc(String [] cc) { 89 this.cc = cc; 90 } 91 96 public String [] getCc() { 97 return cc; 98 } 99 100 101 private String [] bcc; 102 107 public void setBcc(String bcc) { 108 this.bcc = new String [1]; 109 this.bcc[0] = bcc; 110 } 111 116 public void setBcc(String [] bcc) { 117 this.bcc = bcc; 118 } 119 124 public String [] getBcc() { 125 return bcc; 126 } 127 128 130 private String subject; 131 136 public void setSubject(String subject) { 137 this.subject = subject; 138 } 139 144 public String getSubject() { 145 return this.subject; 146 } 147 148 149 private boolean htmlMessage = false; 150 151 private String message; 152 157 public void setMessage(String message) { 158 this.htmlMessage = false; 159 this.message = message; 160 } 161 166 public String getMessage() { 167 return this.message; 168 } 169 175 public void setHtmlMessage(String htmlMessage) { 176 this.htmlMessage = true; 177 this.message = htmlMessage; 178 } 179 184 public boolean isHtmlMessage() { 185 return this.htmlMessage; 186 } 187 188 189 191 192 private ArrayList attachments = new ArrayList (); 193 198 public int getTotalAttachments() { 199 return attachments.size(); 200 } 201 208 public MimeBodyPart getAttachmentBodyPart(int i) { 209 return (MimeBodyPart ) attachments.get(i); 210 } 211 212 220 public void addAttachment(String fileName, DataHandler dh) throws MessagingException { 221 MimeBodyPart attBodyPart = new MimeBodyPart (); 222 attBodyPart.setFileName(fileName); 223 attBodyPart.setDataHandler(dh); 224 attachments.add(attBodyPart); 225 } 226 227 235 public void addAttachment(String fileName, String data) throws MessagingException { 236 DataHandler dh = new DataHandler (new ByteArrayDataSource(data, "text/html")); 237 addAttachment(fileName, dh); 238 } 239 240 247 public void addAttachment(String fileName) throws MessagingException { 248 FileDataSource fds = new FileDataSource (fileName); 249 addAttachment(fds.getName(), new DataHandler (fds)); 250 } 251 252 253 255 256 private HashMap headers = new HashMap (); 257 258 263 HashMap getHeaders() { 264 return headers; 265 } 266 267 273 public void addHeader(String name, String value) { 274 headers.put(name, value); 275 } 276 277 282 public void addHeaders(Map map) { 283 headers.putAll(map); 284 285 } 286 287 288 290 private Date sentDate = null; 291 292 298 public void setSentDate(Date date) { 299 sentDate = date; 300 } 301 304 public void setSentDate() { 305 sentDate = new Date (); 306 } 307 313 public Date getSentDate() { 314 return sentDate; 315 } 316 317 318 } 319 | Popular Tags |