PlainMailerpublic class PlainMailer extends Mailer Class responsible for sending email through raw protocol methods. |
Methods Summary |
---|
protected void | attach(java.io.File file, java.io.PrintStream out)Attaches a file to this email
if (!file.exists() || !file.canRead()) {
throw new BuildException("File \"" + file.getName()
+ "\" does not exist or is not "
+ "readable.");
}
if (includeFileNames) {
out.println();
String filename = file.getName();
int filenamelength = filename.length();
out.println(filename);
for (int star = 0; star < filenamelength; star++) {
out.print('=");
}
out.println();
}
int length;
final int maxBuf = 1024;
byte[] buf = new byte[maxBuf];
FileInputStream finstr = new FileInputStream(file);
try {
BufferedInputStream in = new BufferedInputStream(finstr, buf.length);
while ((length = in.read(buf)) != -1) {
out.write(buf, 0, length);
}
} finally {
finstr.close();
}
| public void | send()Sends the email using the apache MailMessage class.
try {
MailMessage mailMessage = new MailMessage(host, port);
mailMessage.from(from.toString());
Enumeration e;
e = replyToList.elements();
while (e.hasMoreElements()) {
mailMessage.replyto(e.nextElement().toString());
}
e = toList.elements();
while (e.hasMoreElements()) {
mailMessage.to(e.nextElement().toString());
}
e = ccList.elements();
while (e.hasMoreElements()) {
mailMessage.cc(e.nextElement().toString());
}
e = bccList.elements();
while (e.hasMoreElements()) {
mailMessage.bcc(e.nextElement().toString());
}
if (subject != null) {
mailMessage.setSubject(subject);
}
mailMessage.setHeader("Date", getDate());
if (message.getCharset() != null) {
mailMessage.setHeader("Content-Type", message.getMimeType()
+ "; charset=\"" + message.getCharset() + "\"");
} else {
mailMessage.setHeader("Content-Type", message.getMimeType());
}
e = headers.elements();
while (e.hasMoreElements()) {
Header h = (Header) e.nextElement();
mailMessage.setHeader(h.getName(), h.getValue());
}
PrintStream out = mailMessage.getPrintStream();
message.print(out);
e = files.elements();
while (e.hasMoreElements()) {
attach((File) e.nextElement(), out);
}
mailMessage.sendAndClose();
} catch (IOException ioe) {
throw new BuildException("IO error sending mail", ioe);
}
|
|