first commit

This commit is contained in:
MaddoScientisto 2026-03-14 20:04:39 +01:00
commit 4d332ef662
27586 changed files with 3281783 additions and 0 deletions

View file

@ -0,0 +1,353 @@
package com.ablia.mail;
import com.ablia.db.ApplParm;
import com.ablia.db.ResParm;
import com.ablia.util.ByteArrayDataSource;
import com.ablia.util.Debug;
import com.ablia.util.SimpleDateFormat;
import java.text.NumberFormat;
import java.util.Date;
import java.util.Locale;
import java.util.Properties;
import java.util.ResourceBundle;
import java.util.StringTokenizer;
import javax.activation.DataHandler;
import javax.activation.DataSource;
import javax.activation.FileDataSource;
import javax.mail.Address;
import javax.mail.BodyPart;
import javax.mail.Message;
import javax.mail.Multipart;
import javax.mail.SendFailedException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
public class AbMailer extends Debug {
private ResourceBundle propertyResource;
private ApplParm ap;
private String propertyFileName;
private Locale currentLocale;
public AbMailer() {}
public AbMailer(ApplParm theAp) {
this.ap = theAp;
}
public ApplParm getApFull() {
if (this.ap == null)
this.ap = new ApplParm(getDbDriver(), getDbName(), getUser(),
getPassword(), getInitialCons(), getMaxCons(), getTimeout());
return this.ap;
}
protected Locale getCurrentLocale() {
if (this.currentLocale == null)
if (getApFull().getResource("locale") != null) {
String s_locale = getApFull().getResource("locale");
if (s_locale.equals("IT")) {
this.currentLocale = Locale.ITALIAN;
} else if (s_locale.equals("US")) {
this.currentLocale = Locale.US;
} else if (s_locale.equals("UK")) {
this.currentLocale = Locale.UK;
} else {
this.currentLocale = Locale.getDefault();
}
} else {
this.currentLocale = Locale.getDefault();
}
return this.currentLocale;
}
protected SimpleDateFormat getDataFormat() {
if (getResource("dataFormat") != null &&
!getResource("dataFormat").equals(
""))
return new SimpleDateFormat(
getResource("dataFormat"));
return new SimpleDateFormat("dd/MM/yyyy");
}
protected int getDbDriver() {
if (getResource("dbDriver") != null &&
!getResource("dbDriver").equals(
""))
return Integer.parseInt(getResource("dbDriver"));
return 5;
}
protected String getDbName() {
if (getResource("dbName") != null &&
!getResource("dbName").equals(
""))
return getResource("dbName");
return "";
}
protected int getInitialCons() {
if (getResource("initialCons") != null &&
!getResource("initialCons").equals(
""))
return Integer.parseInt(getResource("initialCons"));
return 1;
}
protected String getMailBcc() {
if (getResource("mailBcc") != null &&
!getResource("mailBcc").equals(
""))
return getResource("mailBcc");
return null;
}
protected String getMailCc() {
if (getResource("mailCc") != null &&
!getResource("mailCc").equals(
""))
return getResource("mailCc");
return null;
}
protected boolean getMailDebug() {
if (getResource("mailDebug") != null &&
getResource("mailDebug").toLowerCase().equals("true"))
return true;
return false;
}
protected String getMailFrom() {
if (getResource("mailFrom") != null &&
!getResource("mailFrom").equals(
""))
return getResource("mailFrom");
return null;
}
protected String getMailSMTPServer() {
if (getResource("mailSMTPServer") != null &&
!getResource("mailSMTPServer").equals(
""))
return getResource("mailSMTPServer");
return "";
}
protected String getMailSubject() {
if (getResource("mailSubject") != null &&
!getResource("mailSubject").equals(
""))
return getResource("mailSubject");
return "";
}
protected String getMailTo() {
if (getResource("mailTo") != null &&
!getResource("mailTo").equals(
""))
return getResource("mailTo");
return null;
}
protected int getMaxCons() {
if (getResource("maxCons") != null &&
!getResource("maxCons").equals(
""))
return Integer.parseInt(getResource("maxCons"));
return 20;
}
protected int getMaximumFractionDigits() {
if (getApFull().getResource("maximumFractionDigits").equals(
""))
return 2;
return Integer.parseInt(getApFull()
.getResource("maximumFractionDigits"));
}
protected int getMinimumFractionDigits() {
if (getApFull().getResource("minimumFractionDigits").equals(
""))
return 2;
return Integer.parseInt(getApFull()
.getResource("minimumFractionDigits"));
}
protected NumberFormat getNf() {
NumberFormat nf = NumberFormat.getInstance(getCurrentLocale());
nf.setMaximumFractionDigits(getMaximumFractionDigits());
nf.setMinimumFractionDigits(getMinimumFractionDigits());
return nf;
}
protected String getPassword() {
if (getResource("password") != null &&
!getResource("password").equals(
""))
return getResource("password");
return "";
}
public String getPropertyFileName() {
return (this.propertyFileName == null) ? "ablia" : this.propertyFileName;
}
protected String getResource(String key) {
if (this.propertyResource == null)
this.propertyResource = ResourceBundle.getBundle(getPropertyFileName());
try {
return this.propertyResource.getString(key);
} catch (Exception e) {
handleDebug(e);
return "";
}
}
protected int getTimeout() {
if (getResource("timeout") != null &&
!getResource("timeout").equals(
""))
return Integer.parseInt(getResource("timeout"));
return 300;
}
protected String getUser() {
if (getResource("user") != null &&
!getResource("user").equals(
""))
return getResource("user");
return "";
}
public static boolean isMessageHtml(String fileName) {
String fileType = fileName.substring(fileName.lastIndexOf(".") + 1,
fileName.length()).toLowerCase();
if (fileType.equals("htm") || fileType.equals("html"))
return true;
return false;
}
public void setPropertyFileName(String newPropertyFileName) {
this.propertyFileName = newPropertyFileName;
}
public static ResParm sendMailMessage(MailProperties prop) throws Exception {
ResParm rp;
String subject = null, from = null, cc = null, bcc = null, l_msg = null, l_files = null, l_smtp = null;
boolean isHtml = false;
cc = (prop.getProperty("CC") == null) ? null :
prop.getProperty("CC");
from = (prop.getProperty("FROM") == null) ? null :
prop.getProperty("FROM");
bcc = (prop.getProperty("BCC") == null) ? null :
prop.getProperty("BCC");
subject = (prop.getProperty("SUBJECT") == null) ? "No Subject!!!" :
prop.getProperty("SUBJECT");
String to = (prop.getProperty("TO") == null) ? null :
prop.getProperty("TO");
l_msg = (prop.getProperty("MSG") == null) ? "Mail with no body!!!" :
prop.getProperty("MSG");
l_files = prop.getProperty("FILES");
if (prop.getProperty("SMTP") != null)
l_smtp = prop.getProperty("SMTP");
isHtml = !(prop.getProperty("ISHTML") == null ||
prop.getProperty("ISHTML").equals("false"));
if (to == null)
throw new SendFailedException(
"SendMailMessage(): Can't get user email");
if (l_smtp == null)
throw new SendFailedException(
"SendMailMessage(): No SMTP Server found --> " + l_smtp);
String mailer = "Ablia(c) mail Servlet";
Properties props = System.getProperties();
props.put("mail.smtp.host", l_smtp);
Session mailSession = Session.getDefaultInstance(
props, null);
mailSession.setDebug(false);
try {
MimeMessage msg = new MimeMessage(
mailSession);
msg.setFrom(new InternetAddress(from));
msg.setRecipients(Message.RecipientType.TO,
(Address[])InternetAddress.parse(to, false));
if (cc != null)
msg.setRecipients(Message.RecipientType.CC,
(Address[])InternetAddress.parse(cc, false));
if (bcc != null)
msg.setRecipients(Message.RecipientType.BCC,
(Address[])InternetAddress.parse(bcc, false));
msg.setSubject(subject);
if (l_files == null) {
if (isHtml) {
msg.setDataHandler(new DataHandler(new ByteArrayDataSource(
l_msg, "text/html")));
} else {
msg.setText(l_msg);
}
} else {
MimeMultipart mimeMultipart = new MimeMultipart();
MimeBodyPart mbText = new MimeBodyPart();
if (isHtml) {
mbText.setDataHandler(new DataHandler(
new ByteArrayDataSource(l_msg, "text/html")));
} else {
mbText.setText(l_msg);
}
mimeMultipart.addBodyPart((BodyPart)mbText);
StringTokenizer st = new StringTokenizer(l_files, ",");
while (st.hasMoreElements()) {
MimeBodyPart mbFile = new MimeBodyPart();
FileDataSource fds = new FileDataSource(st.nextToken());
mbFile.setDataHandler(new DataHandler((DataSource)fds));
mbFile.setFileName(fds.getName());
mimeMultipart.addBodyPart((BodyPart)mbFile);
}
msg.setContent((Multipart)mimeMultipart);
}
msg.setHeader("X-Mailer", mailer);
msg.setSentDate(new Date());
Transport.send((Message)msg);
rp = new ResParm(true, "Mail " + to + " with subject:" + subject +
" sent!");
} catch (Exception e) {
rp = new ResParm(false, "CANNOT SEND MAIL TO " + to +
" with subject:" + subject + " and smtp " + l_smtp +
" !!!");
}
return rp;
}
public void sendMailMessage(String to, String l_msg, boolean isHtml) throws Exception {
MailProperties mp = new MailProperties();
if (to != null)
mp.setProperty("TO", to);
if (l_msg != null)
mp.setProperty("MSG", l_msg);
mp.setProperty("ISHTML", isHtml ? "true" : "false");
sendMailMessage(mp);
}
public void sendMailMessage(String from, String to, String cc, String bcc, String subject, String l_msg, boolean isHtml) throws Exception {
MailProperties mp = new MailProperties();
if (from != null)
mp.setProperty("FROM", from);
if (to != null)
mp.setProperty("TO", to);
if (cc != null)
mp.setProperty("CC", cc);
if (bcc != null)
mp.setProperty("BCC", bcc);
if (subject != null)
mp.setProperty("SUBJECT", subject);
if (l_msg != null)
mp.setProperty("MSG", l_msg);
mp.setProperty("ISHTML", isHtml ? "true" : "false");
sendMailMessage(mp);
}
}

View file

@ -0,0 +1,20 @@
package com.ablia.mail;
import javax.mail.Authenticator;
import javax.mail.PasswordAuthentication;
public class MailAuthenticator extends Authenticator {
private String smtpUser;
private String smtpPassword;
public MailAuthenticator(String user, String password) {
this.smtpUser = user;
this.smtpPassword = password;
}
protected PasswordAuthentication getPasswordAuthentication() {
PasswordAuthentication passwordAuthentication = new PasswordAuthentication(this.smtpUser, this.smtpPassword);
return passwordAuthentication;
}
}

View file

@ -0,0 +1,46 @@
package com.ablia.mail;
public class MailEmbededImages {
private String fileName;
private String cid;
private String imageName;
public MailEmbededImages() {}
public MailEmbededImages(String l_filename, String l_cid) {
setFileName(l_filename);
setCid(l_cid);
}
public MailEmbededImages(String l_filename, String l_cid, String l_imageName) {
setFileName(l_filename);
setCid(l_cid);
setImageName(l_imageName);
}
public String getCid() {
return (this.cid == null) ? "" : this.cid;
}
public void setCid(String cid) {
this.cid = cid;
}
public String getFileName() {
return (this.fileName == null) ? "" : this.fileName;
}
public void setFileName(String fileName) {
this.fileName = fileName;
}
public String getImageName() {
return (this.imageName == null) ? "" : this.imageName;
}
public void setImageName(String imageName) {
this.imageName = imageName;
}
}

View file

@ -0,0 +1,423 @@
package com.ablia.mail;
import com.ablia.common.Parm;
import com.ablia.db.ApplParmFull;
import com.ablia.db.DBAdapter;
import com.ablia.db.ResParm;
import com.ablia.log.LogMail;
import com.ablia.util.ByteArrayDataSource;
import com.ablia.util.FileFormatter;
import com.ablia.util.Vectumerator;
import java.util.Date;
import java.util.Properties;
import java.util.StringTokenizer;
import javax.activation.DataHandler;
import javax.activation.DataSource;
import javax.activation.FileDataSource;
import javax.mail.Address;
import javax.mail.Authenticator;
import javax.mail.BodyPart;
import javax.mail.Message;
import javax.mail.Multipart;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
public class MailMessage extends FileFormatter {
private ApplParmFull apFull;
private Parm parm;
public MailMessage(ApplParmFull ap, String l_fileName, boolean useQuestionMark) {
super(l_fileName, useQuestionMark);
setApFull(ap);
}
public MailMessage(ApplParmFull ap, String l_fileName) {
super(l_fileName, false);
setApFull(ap);
}
public MailMessage(ApplParmFull ap) {
super(false);
setApFull(ap);
}
public ApplParmFull getApFull() {
return this.apFull;
}
protected String getResource(String l_key) {
return getApFull().getResource(l_key);
}
public void setApFull(ApplParmFull ap) {
this.apFull = ap;
}
public ResParm sendMailMessage(MailProperties prop, boolean useDefaultParameter) {
String to, aCapo;
ResParm rp = new ResParm(true);
String subject = null, from = null, cc = null, bcc = null, l_msg = null, l_files = null, l_smtp = getMailSMTPServer();
boolean isHtml = false, useSmtpAuth = false;
String to_TEST = null;
long l_id_users = 0L;
long smtpPort = 25L;
if (useDefaultParameter) {
cc = (prop.getProperty("CC") == null) ? getMailCc() : prop.getProperty("CC");
from = (prop.getProperty("FROM") == null) ? getMailFrom() : prop.getProperty("FROM");
bcc = (prop.getProperty("BCC") == null) ? getMailBcc() : prop.getProperty("BCC");
subject = (prop.getProperty("SUBJECT") == null) ? getMailSubject() :
prop.getProperty("SUBJECT");
to = (prop.getProperty("TO") == null) ? getMailTo() : prop.getProperty("TO");
} else {
cc = (prop.getProperty("CC") == null) ? "" : prop.getProperty("CC");
from = (prop.getProperty("FROM") == null) ? getMailFrom() : prop.getProperty("FROM");
bcc = (prop.getProperty("BCC") == null) ? "" : prop.getProperty("BCC");
subject = (prop.getProperty("SUBJECT") == null) ? "" :
prop.getProperty("SUBJECT");
to = (prop.getProperty("TO") == null) ? "" : prop.getProperty("TO");
}
to_TEST = (prop.getProperty("TO_TEST") == null) ? getMailToTest() : prop.getProperty("TO_TEST");
l_id_users = (prop.getProperty("ID_USERS") == null) ? 0L :
Long.parseLong(prop.getProperty("ID_USERS"));
l_msg = getMessage();
if (l_msg == null || l_msg.isEmpty())
l_msg = prop.getProperty("MSG");
if (l_msg == null || l_msg.isEmpty())
l_msg = "Mail with no body!!!";
l_files = prop.getProperty("FILES");
l_smtp = getMailSMTPServer();
if (getFileName() != null) {
isHtml = isHtmlMail();
} else if (prop.getProperty("ISHTML") == null || prop.getProperty("ISHTML").equals("false")) {
isHtml = false;
} else {
isHtml = true;
}
if (to == null) {
rp.setStatus(false);
rp.setMsg("SendMailMessage(): No TO mail specified!");
}
if (isHtml) {
aCapo = "<br>";
} else {
aCapo = "\n";
l_msg = l_msg.replace("<br>", aCapo);
l_msg = l_msg.replace("<BR>", aCapo);
}
if (!to_TEST.isEmpty()) {
l_msg = "----------- TEST MODE -----------" + aCapo + "TO: " + to + aCapo + "CC: " + cc + aCapo + "BCC: " + bcc + aCapo +
"--------------------------------------" + aCapo + aCapo + l_msg;
to = to_TEST;
if (to_TEST.indexOf("@ablia.com") > 0) {
bcc = null;
} else {
bcc = "acolzi@ablia.com";
}
cc = null;
subject = "TEST! - " + subject;
}
useSmtpAuth = (prop.getProperty("SMTP_USE_AUTH") == null) ? (
(getParm("SMTP_USE_AUTH").getNumero() == 1.0D)) : (
prop.getProperty("SMTP_USE_AUTH").equals("true"));
try {
smtpPort = (prop.getProperty("SMTP_PORT") == null) ? getParm("SMTP_PORT").getNumeroLong() :
Long.parseLong(prop.getProperty("SMTP_PORT"));
} catch (Exception e) {}
if (smtpPort == 0L)
smtpPort = 25L;
String mailer = "Ablia(c) mail Servlet";
Properties props = System.getProperties();
props.put("mail.smtp.host", l_smtp);
props.put("mail.smtp.localhost", "127.0.0.1");
props.put("mail.smtp.port", String.valueOf(smtpPort));
MailAuthenticator auth = null;
if (useSmtpAuth) {
props.put("mail.smtp.auth", "true");
getParm("SMTP_STARTTLS").isTrue();
String smtpUser = (prop.getProperty("SMTP_USER") == null) ? getParm("SMTP_USER").getTesto() :
prop.getProperty("SMTP_USER");
String smtpPassword = (prop.getProperty("SMTP_PASSWORD") == null) ?
getParm("SMTP_PASSWORD").getTesto() :
prop.getProperty("SMTP_PASSWORD");
auth = new MailAuthenticator(smtpUser, smtpPassword);
} else {
props.put("mail.smtp.auth", "false");
}
Session mailSession = Session.getDefaultInstance(props, auth);
mailSession.setDebug(true);
try {
MimeMessage msg = new MimeMessage(mailSession);
msg.setFrom(new InternetAddress(from));
msg.setRecipients(Message.RecipientType.TO, (Address[])InternetAddress.parse(to, false));
if (cc != null)
msg.setRecipients(Message.RecipientType.CC, (Address[])InternetAddress.parse(cc, false));
if (bcc != null)
msg.setRecipients(Message.RecipientType.BCC, (Address[])InternetAddress.parse(bcc, false));
msg.setSubject(subject);
if (l_files == null) {
if (isHtml) {
msg.setDataHandler(new DataHandler(new ByteArrayDataSource(l_msg, "text/html")));
} else {
msg.setText(l_msg);
}
} else {
MimeMultipart mimeMultipart = new MimeMultipart();
MimeBodyPart mbText = new MimeBodyPart();
if (isHtml) {
mbText.setDataHandler(new DataHandler(new ByteArrayDataSource(l_msg, "text/html")));
} else {
mbText.setText(l_msg);
}
mimeMultipart.addBodyPart((BodyPart)mbText);
StringTokenizer st = new StringTokenizer(l_files, ",");
while (st.hasMoreElements()) {
MimeBodyPart mbFile = new MimeBodyPart();
FileDataSource fds = new FileDataSource(st.nextToken());
mbFile.setDataHandler(new DataHandler((DataSource)fds));
mbFile.setFileName(fds.getName());
mimeMultipart.addBodyPart((BodyPart)mbFile);
}
msg.setContent((Multipart)mimeMultipart);
}
msg.setHeader("X-Mailer", mailer);
msg.setSentDate(DBAdapter.getToday());
Transport.send((Message)msg);
if (getParm("USE_LOG").isTrue() && getParm("LOG_MAIL_ENABLE").isTrue())
LogMail.addLogMail(getApFull(), prop, subject, l_msg, "Sent", l_id_users);
} catch (Exception e) {
System.out.println("ERRORE MailMessage.sendMailMessage(..): ");
e.printStackTrace();
rp.setStatus(false);
rp.setMsg("CANNOT SEND MAIL TO " + to + " with subject:" + subject + ": " + e.getMessage());
}
return rp;
}
public ResParm sendMailMessageEmbedded(MailProperties prop, Vectumerator embeddedImages) {
String aCapo;
ResParm rp = new ResParm(true);
String subject = null, from = null, cc = null, bcc = null, l_msg = null, l_files = null, l_smtp = getMailSMTPServer();
boolean isHtml = false, useSmtpAuth = false;
String to_TEST = null;
long smtpPort = 25L;
cc = (prop.getProperty("CC") == null) ? getMailCc() : prop.getProperty("CC");
from = (prop.getProperty("FROM") == null) ? getMailFrom() : prop.getProperty("FROM");
bcc = (prop.getProperty("BCC") == null) ? getMailBcc() : prop.getProperty("BCC");
subject = (prop.getProperty("SUBJECT") == null) ? getMailSubject() : prop.getProperty("SUBJECT");
String to = (prop.getProperty("TO") == null) ? getMailTo() : prop.getProperty("TO");
to_TEST = (prop.getProperty("TO_TEST") == null) ? getMailToTest() : prop.getProperty("TO_TEST");
l_msg = (prop.getProperty("MSG") == null) ? "Mail with no body!!!" : prop.getProperty("MSG");
l_files = prop.getProperty("FILES");
if (prop.getProperty("SMTP") != null)
l_smtp = prop.getProperty("SMTP");
if (getFileName() != null) {
isHtml = isHtmlMail();
} else if (prop.getProperty("ISHTML") == null || prop.getProperty("ISHTML").equals("false")) {
isHtml = false;
} else {
isHtml = true;
}
if (to == null) {
rp.setStatus(false);
rp.setMsg("SendMailMessage(): No TO mail specified!");
}
if (isHtml) {
aCapo = "<br>";
} else {
aCapo = "\n";
l_msg = l_msg.replace("<br>", aCapo);
l_msg = l_msg.replace("<BR>", aCapo);
}
if (!to_TEST.isEmpty()) {
l_msg = "----------- TEST MODE -----------" + aCapo + "TO: " + to + aCapo + "CC: " + cc + aCapo + "BCC: " + bcc + aCapo +
"--------------------------------------" + aCapo + aCapo + l_msg;
to = to_TEST;
bcc = null;
cc = null;
subject = "TEST! - " + subject;
}
useSmtpAuth = (prop.getProperty("SMTP_USE_AUTH") == null) ? (
(getParm("SMTP_USE_AUTH").getNumero() == 1.0D)) : (
prop.getProperty("SMTP_USE_AUTH").equals("true"));
final String smtpUser = (prop.getProperty("SMTP_USER") == null) ? getParm("SMTP_USER").getTesto() :
prop.getProperty("SMTP_USER");
final String smtpPassword = (prop.getProperty("SMTP_PASSWORD") == null) ?
getParm("SMTP_PASSWORD").getTesto() :
prop.getProperty("SMTP_PASSWORD");
try {
smtpPort = (prop.getProperty("SMTP_PORT") == null) ? getParm("SMTP_PORT").getNumeroLong() :
Long.parseLong(prop.getProperty("SMTP_PORT"));
} catch (Exception e) {}
if (smtpPort == 0L)
smtpPort = 25L;
String mailer = "Ablia(c) mail Servlet";
Properties props = System.getProperties();
props.put("mail.smtp.host", l_smtp);
props.put("mail.smtp.localhost", "127.0.0.1");
Authenticator auth = null;
if (useSmtpAuth) {
props.put("mail.smtp.auth", "true");
if (getParm("SMTP_STARTTLS").isTrue())
props.put("mail.smtp.starttls.enable", "true");
auth = new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
PasswordAuthentication passwordAuthentication = new PasswordAuthentication(smtpUser, smtpPassword);
return passwordAuthentication;
}
};
}
Session mailSession = Session.getDefaultInstance(props, auth);
mailSession.setDebug(true);
try {
MimeBodyPart mimeBodyPart1;
MimeMessage msg = new MimeMessage(mailSession);
msg.setFrom(new InternetAddress(from));
msg.setRecipients(Message.RecipientType.TO, (Address[])InternetAddress.parse(to, false));
if (cc != null)
msg.setRecipients(Message.RecipientType.CC, (Address[])InternetAddress.parse(cc, false));
if (bcc != null)
msg.setRecipients(Message.RecipientType.BCC, (Address[])InternetAddress.parse(bcc, false));
msg.setSubject(subject);
MimeMultipart mimeMultipart1 = new MimeMultipart("mixed");
MimeMultipart mimeMultipart2 = new MimeMultipart("related");
MimeBodyPart mbText = new MimeBodyPart();
mbText.setDataHandler(new DataHandler(new ByteArrayDataSource(l_msg, "text/html")));
mimeMultipart2.addBodyPart((BodyPart)mbText);
while (embeddedImages.hasMoreElements()) {
MailEmbededImages mei = embeddedImages.nextElement();
String imagefile = mei.getFileName();
String cid = mei.getCid();
MimeBodyPart rel_bpi = new MimeBodyPart();
FileDataSource ifds = new FileDataSource(imagefile);
rel_bpi.setFileName(ifds.getName());
rel_bpi.setText(mei.getImageName());
rel_bpi.setDataHandler(new DataHandler((DataSource)ifds));
rel_bpi.setHeader("Content-ID", "<" + cid + ">");
rel_bpi.setDisposition("inline");
mimeMultipart2.addBodyPart((BodyPart)rel_bpi);
}
BodyPart attach = null;
if (l_files != null && !l_files.isEmpty()) {
MimeMultipart mimeMultipart = new MimeMultipart();
mimeBodyPart1 = new MimeBodyPart();
StringTokenizer st = new StringTokenizer(l_files, ",");
while (st.hasMoreElements()) {
MimeBodyPart mbFile = new MimeBodyPart();
FileDataSource fds = new FileDataSource(st.nextToken());
mbFile.setDataHandler(new DataHandler((DataSource)fds));
mbFile.setFileName(fds.getName());
mimeMultipart.addBodyPart((BodyPart)mbFile);
}
mimeBodyPart1.setContent((Multipart)mimeMultipart);
}
MimeBodyPart mimeBodyPart2 = new MimeBodyPart();
mimeBodyPart2.setContent((Multipart)mimeMultipart2);
mimeMultipart1.addBodyPart((BodyPart)mimeBodyPart2);
if (mimeBodyPart1 != null)
mimeMultipart1.addBodyPart((BodyPart)mimeBodyPart1);
msg.setContent((Multipart)mimeMultipart1);
msg.setHeader("X-Mailer", mailer);
msg.setSentDate(new Date());
Transport.send((Message)msg);
} catch (Exception e) {
rp.setStatus(false);
rp.setMsg("CANNOT SEND MAIL TO " + to + " with subject:" + subject + ": " + e.getMessage());
}
return rp;
}
public String getMailBcc() {
if (!getParm("BCC").getTesto().equals(""))
return getParm("BCC").getTesto();
if (!getResource("BCC").equals(""))
return getResource("BCC");
return null;
}
public String getMailCc() {
if (!getParm("CC").getTesto().equals(""))
return getParm("CC").getTesto();
if (!getResource("CC").equals(""))
return getResource("CC");
return null;
}
public String getMailFrom() {
if (!getParm("FROM").getTesto().equals(""))
return getParm("FROM").getTesto();
if (!getResource("FROM").equals(""))
return getResource("FROM");
return null;
}
protected String getMailSMTPServer() {
if (!getParm("SMTP").getTesto().equals(""))
return getParm("SMTP").getTesto();
if (!getResource("SMTP").equals(""))
return getResource("SMTP");
return "";
}
public String getMailSubject() {
if (!getParm("SUBJECT").getTesto().equals(""))
return getParm("SUBJECT").getTesto();
if (!getResource("SUBJECT").equals(""))
return getResource("SUBJECT");
return "";
}
public String getMailTo() {
if (!getParm("TO").getTesto().equals(""))
return getParm("TO").getTesto();
if (!getResource("TO").equals(""))
return getResource("TO");
return null;
}
public boolean isHtmlMail() {
if (getFileName() == null)
return false;
if (getFileName().toLowerCase().endsWith(".html") || getFileName().toLowerCase().endsWith(".htm"))
return true;
return false;
}
public Parm getParm(String theKey) {
if (this.parm == null)
this.parm = new Parm(getApFull());
try {
this.parm.findByCodice(theKey);
return this.parm;
} catch (Exception e) {
e.printStackTrace();
return this.parm;
}
}
public ResParm sendMailMessageSystem(String l_to, String l_subject, boolean useDefaultParameter) {
return sendMailMessage(l_to, l_subject, useDefaultParameter, 1L);
}
public ResParm sendMailMessage(String l_to, String l_subject, boolean useDefaultParameter, long l_id_users) {
MailProperties mp = new MailProperties();
if (l_to != null)
mp.setProperty("TO", l_to);
if (l_subject != null)
mp.setProperty("SUBJECT", l_subject);
mp.setProperty("MSG", getMessage());
mp.setProperty("ID_USERS", String.valueOf(l_id_users));
return sendMailMessage(mp, useDefaultParameter);
}
protected String getMailToTest() {
if (!getParm("TO_TEST").getTesto().isEmpty())
return getParm("TO_TEST").getTesto();
return "";
}
}

View file

@ -0,0 +1,57 @@
package com.ablia.mail;
import java.util.Properties;
public class MailProperties extends Properties {
private static final long serialVersionUID = 1L;
public static final String MAIL_TO = "TO";
public static final String MAIL_TO_TEST = "TO_TEST";
public static final String MAIL_TO_DEBUG = "TO_DEBUG";
public static final String MAIL_CC = "CC";
public static final String MAIL_ID_USERS = "ID_USERS";
public static final String MAIL_SUBJECT = "SUBJECT";
public static final String MAIL_ISHTML = "ISHTML";
public static final String MAIL_FROM = "FROM";
public static final String MAIL_MSG = "MSG";
public static final String MAIL_FILES = "FILES";
public static final String MAIL_SMTP = "SMTP";
public static final String MAIL_SMTP_USER = "SMTP_USER";
public static final String MAIL_SMTP_PASSWORD = "SMTP_PASSWORD";
public static final String MAIL_SMTP_PORT = "SMTP_PORT";
public static final String MAIL_SMTP_USE_AUTH = "SMTP_USE_AUTH";
public static final String MAIL_SMTP_STARTTLS = "SMTP_STARTTLS";
public static final String PROP_SMTP_SERVER = "SMTP";
public static final String MSG_HTML_HEADER = "<html xmlns=\"http://www.w3.org/1999/xhtml\"><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" /><title>Mail Message</title></head><body style=\"margin:0; padding:0\">";
public static final String MSG_HTML_FOOTER = "</body></html>";
public static final String MAIL_NO_REPLY = "NO_REPLY";
public static final String MAIL_TOT_IND_BCC = "MAILING_LIST_TOT_IND_BCC";
public static final String MAIL_BCC = "BCC";
public MailProperties() {}
public MailProperties(Properties defaults) {
super(defaults);
}
}

View file

@ -0,0 +1 @@
package com.ablia.mail;