throw new MessagingException(nspe.getMessage(), nspe);
}
} // fi (Session.getInstance())
} // fi (oMailSession)
MimeMessage oMsg;
InternetAddress oFrom, oTo;
MimeMultipart oAltParts = new MimeMultipart("alternative");
// Set alternative plain/text part to avoid spam filters as much as possible
MimeBodyPart oMsgTextPart = new MimeBodyPart();
oMsgTextPart.setText("This message is HTML, but your e-mail client is not capable of rendering HTML messages", "UTF-8", "plain");
MimeBodyPart oMsgBodyPart = new MimeBodyPart();
try {
if (null==getParameter("tx_sender"))
oFrom = new InternetAddress(getParameter("tx_from"));
else
oFrom = new InternetAddress(getParameter("tx_from"), getParameter("tx_sender"));
if (DebugFile.trace) DebugFile.writeln("to: " + oAtm.getStringNull(DB.tx_email, "ERROR Atom[" + String.valueOf(oAtm.getInt(DB.pg_atom)) + "].tx_email is null!"));
oTo = new InternetAddress(oAtm.getString(DB.tx_email), oAtm.getStringNull(DB.tx_name,"") + " " + oAtm.getStringNull(DB.tx_surname,""));
}
catch (AddressException adre) {
if (DebugFile.trace) DebugFile.writeln("AddressException " + adre.getMessage() + " job " + getString(DB.gu_job) + " atom " + String.valueOf(oAtm.getInt(DB.pg_atom)));
oFrom = null;
oTo = null;
throw new MessagingException ("AddressException " + adre.getMessage() + " job " + getString(DB.gu_job) + " atom " + String.valueOf(oAtm.getInt(DB.pg_atom)));
}
if (DebugFile.trace) DebugFile.writeln("new MimeMessage([Session])");
oMsg = new MimeMessage(oMailSession);
oMsg.setSubject(getParameter("tx_subject"));
oMsg.setFrom(oFrom);
if (DebugFile.trace) DebugFile.writeln("MimeMessage.addRecipient(MimeMessage.RecipientType.TO, " + oTo.getAddress());
oMsg.addRecipient(MimeMessage.RecipientType.TO, oTo);
String sSrc = null, sCid = null;
try {
// Insert Web Beacon just before </BODY> tag
if (Yes.equals(getParameter("bo_webbeacon"))) {
int iEndBody = Gadgets.indexOfIgnoreCase(oReplaced, "</body>", 0);
if (iEndBody>0) {
String sWebBeaconDir = getProperty("webbeacon");
if (sWebBeaconDir==null) {
sWebBeaconDir = Gadgets.chomp(getParameter("webserver"),'/')+"hipermail/";
} else if (sWebBeaconDir.trim().length()==0) {
sWebBeaconDir = Gadgets.chomp(getParameter("webserver"),'/')+"hipermail/";
}
oReplaced = oReplaced.substring(0, iEndBody)+"<img src=\""+Gadgets.chomp(sWebBeaconDir,'/')+"web_beacon.jsp?gu_job="+getString(DB.gu_job)+"&pg_atom="+String.valueOf(oAtm.getInt(DB.pg_atom))+"&gu_company="+oAtm.getStringNull(DB.gu_company,"")+"&gu_contact="+oAtm.getStringNull(DB.gu_contact,"")+"&tx_email="+oAtm.getStringNull(DB.tx_email,"")+"\" width=\"1\" height=\"1\" border=\"0\" alt=\"\" />"+oReplaced.substring(iEndBody);
} // fi </body>
} // fi (bo_webbeacon)
// Images may be attached into message or be absolute http source references
if (Yes.equals(getParameter("bo_attachimages"))) {
if (DebugFile.trace) DebugFile.writeln("BodyPart.setText("+oReplaced.replace('\n',' ')+",UTF-8,html)");
oMsgBodyPart.setText(oReplaced, "UTF-8", "html");
// Create a related multi-part to combine the parts
MimeMultipart oRelatedMultiPart = new MimeMultipart("related");
oRelatedMultiPart.addBodyPart(oMsgBodyPart);
Iterator<String> oImgs = oDocumentImages.keySet().iterator();
while (oImgs.hasNext()) {
MimeBodyPart oImgBodyPart = new MimeBodyPart();
sCid = oImgs.next();
sSrc = oDocumentImages.get(sCid);
if (sSrc.startsWith("www."))
sSrc = "http://" + sSrc;
if (sSrc.startsWith("http://") || sSrc.startsWith("https://")) {
oImgBodyPart.setDataHandler(new DataHandler(new URL(sSrc)));
}
else {
oImgBodyPart.setDataHandler(new DataHandler(new FileDataSource(sSrc)));
}
oImgBodyPart.setContentID(sCid);
oImgBodyPart.setDisposition(oImgBodyPart.INLINE);
oImgBodyPart.setFileName(sCid);
// Add part to multi-part
oRelatedMultiPart.addBodyPart(oImgBodyPart);
} // wend
MimeBodyPart oTextHtmlRelated = new MimeBodyPart();
oTextHtmlRelated.setContent(oRelatedMultiPart);
oAltParts.addBodyPart(oMsgTextPart);
oAltParts.addBodyPart(oTextHtmlRelated);
MimeMultipart oSentMsgParts = new MimeMultipart("mixed");
MimeBodyPart oMixedPart = new MimeBodyPart();
oMixedPart.setContent(oAltParts);
oSentMsgParts.addBodyPart(oMixedPart);
oMsg.setContent(oSentMsgParts);
}
else {
if (DebugFile.trace) DebugFile.writeln("BodyPart.setText("+oReplaced.replace('\n',' ')+",UTF-8,html)");
oMsgBodyPart.setText(oReplaced, "UTF-8", "html");
oAltParts.addBodyPart(oMsgTextPart);
oAltParts.addBodyPart(oMsgBodyPart);
oMsg.setContent(oAltParts);
}
oMsg.saveChanges();
if (DebugFile.trace) DebugFile.writeln("Transport.sendMessage([MimeMessage], MimeMessage.getAllRecipients())");
oMailTransport.sendMessage(oMsg, oMsg.getAllRecipients());
// ************************************************************
// Decrement de count of atoms peding of processing at this job
iPendingAtoms--;
}