/*
* don't bother me w/ null messages or no addreses
*/
if (message == null ) {
throw new MessagingException("Null message");
}
if (addresses == null || addresses.length == 0) {
throw new MessagingException("Null or empty address array");
}
SendStatus[] stat = new SendStatus[addresses.length];
try {
/*
* create socket and connect to server.
*/
Socket s = getConnectedSocket();
/*
* receive welcoming message
*/
if (!getWelcome(s)) {
throw new MessagingException("Error in getting welcome msg");
}
/*
* say hello
*/
if (!sendHelo(s)) {
throw new MessagingException("Error in saying HELO to server");
}
/*
* send sender
*/
if (!sendMailFrom(s, message.getFrom())) {
throw new MessagingException("Error in setting the MAIL FROM");
}
/*
* send recipients. Only send if not null or "", and just ignore
* (but log) any errors
*/
for (int i=0; i < addresses.length; i++) {
String to = addresses[i].toString();
int status = SendStatus.SUCCESS;
if (to != null && !"".equals(to)) {
if (!sendRcptTo(s, to)) {
// this means it didn't like our recipient. I say we keep
// going
if (this.session.getDebug()) {
this.session.getDebugOut().println("ERROR setting recipient " + to);
}
status = SendStatus.FAIL;
}
}
else {
status = SendStatus.FAIL;
}
stat[i] = new SendStatus(status, to);
}
/*
* send data
*/
if (!sendData(s, message)) {
throw new MessagingException("Error sending data");
}
/*
* say goodbye
*/
sendQuit(s);
try {
s.close();
}
catch (IOException e) {
//
// TODO - should we just eat this? We have delivered the msg...
//
e.printStackTrace();
}
}
catch (SMTPTransportException e) {
throw new MessagingException("error", e);
}
catch (MalformedSMTPReplyException e) {
throw new MessagingException("error", e);
}
return stat;
}