*/
public void send(TransferObject tobj) throws IntegrationException
{
if (!m_channel.isSendable())
{
throw new IntegrationException("err.rpc.notSender", new Object[]{m_channel.getName()});
}
if (s_logger.isDebugEnabled())
{
s_logger.debug("Sending a message on channel \"" + m_channel.getName() + "\"");
s_logger.dump(tobj);
}
MailConnection con = null;
try
{
con = m_factory.openConnection(tobj);
MimeMessage msg = con.createMessage();
List/*<Address>*/ list = new ArrayList/*<Address>*/(1);
if (addAddresses(list, tobj.findValue(Mail.FROM, m_channel.getFrom())).isEmpty())
{
msg.setFrom();
}
else if (list.size() == 1)
{
msg.setFrom((Address)list.get(0));
}
else // FROM field cannot have more than 1 value
{
throw new IntegrationException("err.rpc.mailFromCount");
}
list.clear();
if (addAddresses(list, tobj.findValue(Mail.TO)).isEmpty()) // TO field required
{
throw new IntegrationException("err.rpc.mailToMissing");
}
msg.setRecipients(javax.mail.Message.RecipientType.TO,
(Address[])list.toArray(new Address[list.size()]));
list.clear();
if (!addAddresses(list, tobj.findValue(Mail.CC)).isEmpty())
{
msg.setRecipients(javax.mail.Message.RecipientType.CC,
(Address[])list.toArray(new Address[list.size()]));
}
list.clear();
if (!addAddresses(list, tobj.findValue(Mail.BCC)).isEmpty())
{
msg.setRecipients(javax.mail.Message.RecipientType.BCC,
(Address[])list.toArray(new Address[list.size()]));
}
list.clear();
if (!addAddresses(list, tobj.findValue(Mail.REPLY)).isEmpty())
{
msg.setReplyTo((Address[])list.toArray(new Address[list.size()]));
}
String sSubject = (String)tobj.findValue(Mail.SUBJECT);
if (sSubject != null)
{
msg.setSubject(sSubject);
}
msg.setSentDate(new Date());
setContent(msg, tobj);
if (s_logger.isDebugEnabled())
{
s_logger.debug("Sending an e-mail to " + msg.getRecipients(RecipientType.TO) +
" from " + msg.getFrom());
if (s_logger.isDumpEnabled())
{
Object headers = tobj.findValue(Mail.HEADERS);
s_logger.dump(
"Subject: \"" + msg.getSubject() + "\"" + SysUtil.LINE_SEP +
((headers != null) ? "Headers: " + headers + SysUtil.LINE_SEP : "") +
tobj.findValue(Mail.BODY));
}
}
Transport.send(msg);
m_sentCounter.add(1);
}
catch (Exception e)
{
throw new IntegrationException("err.rpc.mail", e);
}
finally
{
if (con != null)
{