fromAddress = new InternetAddress(fromAddressString);
}
}
catch (Exception e)
{
throw new XException(Constants.LOCATION_EXTERN,
Constants.LAYER_TECHNICAL,
Constants.PACKAGE_TECHNICAL_MAIL, "0", e);
}
mUser = config.getValueOptional(Constants.CHAPTER_SYSTEM, mDestination
.getName(), "User");
if (mUser != null)
{
mPassword = config.getValue(Constants.CHAPTER_SYSTEM, mDestination
.getName(), "Password");
}
/*
* Setting the session
*/
Properties props = new Properties();
props.put("mail.smtp.host", host);
if (mUser != null)
{
props.put("mail.smtp.auth", "true");
}
Authenticator auth = new MyAuthenticator();
Session session = Session.getInstance(props, auth);
try
{
/*
* Creating the message
*/
MimeMessage msg = new MimeMessage(session);
if (mUser != null)
{
msg.setHeader("AUTH", "PLAIN");
}
msg.setFrom(fromAddress);
msg.setRecipients(Message.RecipientType.TO, toAddresses);
msg.setSubject(subject);
msg.setSentDate(new Date());
msg.setText(callData, getEncoding());
/*
* Sending the message
*/
Transport.send(msg);
}
catch (Exception e) // (MessagingException e) per casting below
{ // HP Java runtime did not recognise MessagingException as a subtype
// of
// Throwable.
try
{
MessagingException me = (MessagingException) e;
Exception nextException = me.getNextException();
if (nextException != null)
{
Trace.error(nextException.getMessage());
if (nextException instanceof SendFailedException)
{
Address[] invalid = ((SendFailedException) nextException)
.getInvalidAddresses();
for (int i = 0; i < invalid.length; i++)
{
Trace.error("Invalid address: "
+ ((InternetAddress) invalid[i])
.getAddress());
}
}
}
}
catch (ClassCastException ce)
{}
throw new XException(Constants.LOCATION_EXTERN,
Constants.LAYER_TECHNICAL,
Constants.PACKAGE_TECHNICAL_MAIL, "0", e);
}
return null;
}