*
* @see org.apache.tools.mail.MailMessage
*/
public void send() {
try {
MailMessage mailMessage = new MailMessage(host, port);
mailMessage.from(from.toString());
Enumeration e;
boolean atLeastOneRcptReached = false;
e = replyToList.elements();
while (e.hasMoreElements()) {
mailMessage.replyto(e.nextElement().toString());
}
e = toList.elements();
while (e.hasMoreElements()) {
String to = e.nextElement().toString();
try {
mailMessage.to(to);
atLeastOneRcptReached = true;
} catch (IOException ex) {
badRecipient(to, ex);
}
}
e = ccList.elements();
while (e.hasMoreElements()) {
String to = e.nextElement().toString();
try {
mailMessage.cc(to);
atLeastOneRcptReached = true;
} catch (IOException ex) {
badRecipient(to, ex);
}
}
e = bccList.elements();
while (e.hasMoreElements()) {
String to = e.nextElement().toString();
try {
mailMessage.bcc(to);
atLeastOneRcptReached = true;
} catch (IOException ex) {
badRecipient(to, ex);
}
}
if (!atLeastOneRcptReached) {
throw new BuildException("Couldn't reach any recipient");
}
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());
}
if (headers != null) {
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);
}
}