List of usage examples for org.apache.commons.mail ImageHtmlEmail ImageHtmlEmail
ImageHtmlEmail
From source file:gribbit.util.SendEmail.java
/** Send an email. Don't forget to use fully-qualified URLs in the message body. */ public static void sendEmail(final String toName, final String to, final String subject, final DataModel message, final String messagePlainText) { // Queue sending of email in a new thread GribbitServer.vertx.executeBlocking(future -> { if (GribbitProperties.SMTP_SERVER == null || GribbitProperties.SEND_EMAIL_ADDRESS == null || GribbitProperties.SEND_EMAIL_PASSWORD == null || GribbitProperties.SEND_EMAIL_ADDRESS == null || GribbitProperties.SEND_EMAIL_NAME == null) { throw new RuntimeException("SMTP is not fully configured in the properties file"); }/*from w w w .j a va2 s . c om*/ String fullEmailAddr = "\"" + toName + "\" <" + to + ">"; try { HtmlEmail email = new ImageHtmlEmail(); email.setDebug(false); email.setHostName(GribbitProperties.SMTP_SERVER); email.setSmtpPort(GribbitProperties.SMTP_PORT); email.setAuthenticator(new DefaultAuthenticator(GribbitProperties.SEND_EMAIL_ADDRESS, GribbitProperties.SEND_EMAIL_PASSWORD)); email.setStartTLSRequired(true); email.addTo(to, toName); email.setFrom(GribbitProperties.SEND_EMAIL_ADDRESS, GribbitProperties.SEND_EMAIL_NAME); email.setSubject(subject); email.setHtmlMsg(message.toString()); email.setTextMsg(messagePlainText); email.send(); Log.info("Sent email to " + fullEmailAddr + " : " + subject); } catch (EmailException e) { Log.exception("Failure while trying to send email to " + fullEmailAddr + " : " + subject, e); } future.complete(); }, res -> { if (res.failed()) { Log.error("Exception while trying to send email"); } }); }
From source file:com.pax.pay.trans.receipt.paperless.AReceiptEmail.java
public int sendHtmlEmail(EmailInfo emailInfo, String emailAddress, String subject, String content, Bitmap pic) { String placeHolder = "<img/>"; String htmlMsg = "<html><body>" + placeHolder + "</body></html>"; try {/* w w w . ja va 2s. c o m*/ ImageHtmlEmail email = new ImageHtmlEmail(); setBaseInfo(emailInfo, email); File file = Convert(pic, "receipt_tmp.jpg"); email.setDataSourceResolver(new DataSourceFileResolver(file)); String cid = email.embed(file); // cid String img = "<img src='cid:" + cid + "'/>"; // img?cid htmlMsg = htmlMsg.replace(placeHolder, img); // ?html?? email.setSubject(subject); email.setTextMsg(content); email.setHtmlMsg(htmlMsg); email.addTo(emailAddress); email.send(); } catch (EmailException | IOException e) { e.printStackTrace(); return -1; } return 0; }
From source file:com.qwazr.connectors.EmailConnector.java
@JsonIgnore public ImageHtmlEmail getNewImageHtmlEmail(Map<String, Object> params) throws EmailException { ImageHtmlEmail email = new ImageHtmlEmail(); generic_params(email, params);/*from w w w. j a v a 2s . co m*/ return email; }
From source file:com.qwazr.library.email.EmailConnector.java
@JsonIgnore public ImageHtmlEmail getNewImageHtmlEmail(final Map<String, Object> params) throws EmailException { ImageHtmlEmail email = new ImageHtmlEmail(); generic_params(email, params);// w w w . j av a2 s . c om return email; }
From source file:com.hurence.logisland.processor.mailer.MailerProcessor.java
@Override public Collection<Record> process(ProcessContext context, Collection<Record> records) { if (debug) {// www . ja va2 s . c om logger.info("Mailer Processor records input: " + records); } final Collection<Record> failedRecords = new ArrayList<>(); /** * Transform the records into mails and send them */ for (Record record : records) { String mailText = getStringField(record, FIELD_MAIL_TEXT); boolean text = (mailText != null); String mailHtml = getStringField(record, FIELD_MAIL_HTML); boolean html = (mailHtml != null); Field mailUseTemplate = record.getField(FIELD_MAIL_USE_TEMPLATE); boolean useTemplate = (mailUseTemplate != null); if (html || text || useTemplate) { // Ok, there is a mail to send. First retrieve some potential embedded overwritten configuration fields String[] finalMailTos = mailTos; String finalMailFromAddress = mailFromAddress; String finalMailFromName = mailFromName; String finalMailBounceAddress = mailBounceAddress; String finalMailReplyToAddress = mailReplyToAddress; String finalMailSubject = mailSubject; /** * Overwrite some variables with special fields in the record if any and this is allowed */ if (allowFieldsOverwriting) { String recordMailFromAddress = getStringField(record, FIELD_MAIL_FROM_ADDRESS); if (recordMailFromAddress != null) { finalMailFromAddress = recordMailFromAddress; } String recordMailFromName = getStringField(record, FIELD_MAIL_FROM_NAME); if (recordMailFromName != null) { finalMailFromName = recordMailFromName; } String recordMailBounceAddress = getStringField(record, FIELD_MAIL_BOUNCE_ADDRESS); if (recordMailBounceAddress != null) { finalMailBounceAddress = recordMailBounceAddress; } String recordMailReplyToAddress = getStringField(record, FIELD_MAIL_REPLYTO_ADDRESS); if (recordMailReplyToAddress != null) { finalMailReplyToAddress = recordMailReplyToAddress; } String recordMailSubject = getStringField(record, FIELD_MAIL_SUBJECT); if (recordMailSubject != null) { finalMailSubject = recordMailSubject; } String recordMailTo = getStringField(record, FIELD_MAIL_TO); if (recordMailTo != null) { finalMailTos = parseMailTo(recordMailTo); } } if (finalMailFromAddress == null) { record.addError(ProcessError.UNKNOWN_ERROR.getName(), "No From address defined"); failedRecords.add(record); continue; } if (finalMailBounceAddress == null) { record.addError(ProcessError.UNKNOWN_ERROR.getName(), "No Bounce address defined"); failedRecords.add(record); continue; } if (html || useTemplate) { if (html && useTemplate) { record.addError(ProcessError.UNKNOWN_ERROR.getName(), "Record has both " + FIELD_MAIL_USE_TEMPLATE + " and " + FIELD_MAIL_HTML + " fields. Only one of them is expected."); failedRecords.add(record); continue; } // HTML mail try { /** * Create and fill the mail */ ImageHtmlEmail htmlEmail = new ImageHtmlEmail(); // Set From info if (finalMailFromName != null) { htmlEmail.setFrom(finalMailFromAddress, finalMailFromName); } else { htmlEmail.setFrom(finalMailFromAddress); } htmlEmail.setBounceAddress(finalMailBounceAddress); if (finalMailReplyToAddress != null) { htmlEmail.addReplyTo(finalMailReplyToAddress); } htmlEmail.setSubject(finalMailSubject); // Allow to retrieve embedded images of the html template from the classpath (jar files) htmlEmail.setDataSourceResolver(new DataSourceClassPathResolver()); // Compute final HTML body from template and record fields String htmlBody = null; if (useTemplate) { htmlBody = createHtml(record); if (htmlBody == null) { // Error. Error message has already been set in createHtml: just add to failed record and // continue with next record failedRecords.add(record); continue; } } else { // html htmlBody = mailHtml; } htmlEmail.setHtmlMsg(htmlBody); // Add alternative text mail if any defined if (text) { htmlEmail.setTextMsg(mailText); } // Set To info if (finalMailTos.length == 0) { record.addError(ProcessError.UNKNOWN_ERROR.getName(), "No mail recipient."); failedRecords.add(record); continue; } for (String mailTo : finalMailTos) { htmlEmail.addTo(mailTo); } /** * Set sending parameters */ htmlEmail.setHostName(smtpServer); htmlEmail.setSmtpPort(smtpPort); if ((smtpSecurityUsername != null) && (smtpSecurityPassword != null)) { htmlEmail.setAuthentication(smtpSecurityUsername, smtpSecurityPassword); } htmlEmail.setSSLOnConnect(smtpSecuritySsl); // Send the mail htmlEmail.send(); } catch (EmailException ex) { record.addError(ProcessError.UNKNOWN_ERROR.getName(), "Unable to send email: " + ex.getMessage()); failedRecords.add(record); } } else { // Only text mail try { /** * Create and fill the mail */ SimpleEmail textEmail = new SimpleEmail(); // Set From info if (finalMailFromName != null) { textEmail.setFrom(finalMailFromAddress, finalMailFromName); } else { textEmail.setFrom(finalMailFromAddress); } textEmail.setBounceAddress(finalMailBounceAddress); if (finalMailReplyToAddress != null) { textEmail.addReplyTo(finalMailReplyToAddress); } textEmail.setSubject(finalMailSubject); textEmail.setMsg(mailText); // Set To info if (finalMailTos.length == 0) { record.addError(ProcessError.UNKNOWN_ERROR.getName(), "No mail recipient."); failedRecords.add(record); continue; } for (String mailTo : finalMailTos) { textEmail.addTo(mailTo); } /** * Set sending parameters */ textEmail.setHostName(smtpServer); textEmail.setSmtpPort(smtpPort); if ((smtpSecurityUsername != null) && (smtpSecurityPassword != null)) { textEmail.setAuthentication(smtpSecurityUsername, smtpSecurityPassword); } textEmail.setSSLOnConnect(smtpSecuritySsl); // Send the mail textEmail.send(); } catch (EmailException ex) { record.addError(ProcessError.UNKNOWN_ERROR.getName(), "Unable to send email: " + ex.getMessage()); failedRecords.add(record); } } } } if (debug) { logger.info("Mailer Processor records output: " + records); } return failedRecords; }
From source file:com.hurence.logisland.processor.SendMail.java
@Override public Collection<Record> process(ProcessContext context, Collection<Record> records) { if (debug) {//from ww w . j a va2 s. c o m logger.info("SendMail Processor records input: " + records); } final Collection<Record> failedRecords = new ArrayList<>(); /** * Transform the records into mails and send them */ for (Record record : records) { String mailText = getStringField(record, FIELD_MAIL_TEXT); boolean text = (mailText != null); String mailHtml = getStringField(record, FIELD_MAIL_HTML); boolean html = (mailHtml != null); Field mailUseTemplate = record.getField(FIELD_MAIL_USE_TEMPLATE); boolean useTemplate = (mailUseTemplate != null); if (html || text || useTemplate) { // Ok, there is a mail to send. First retrieve some potential embedded overwritten configuration fields String[] finalMailTos = mailTos; String finalMailFromAddress = mailFromAddress; String finalMailFromName = mailFromName; String finalMailBounceAddress = mailBounceAddress; String finalMailReplyToAddress = mailReplyToAddress; String finalMailSubject = mailSubject; /** * Overwrite some variables with special fields in the record if any and this is allowed */ if (allowFieldsOverwriting) { String recordMailFromAddress = getStringField(record, FIELD_MAIL_FROM_ADDRESS); if (recordMailFromAddress != null) { finalMailFromAddress = recordMailFromAddress; } String recordMailFromName = getStringField(record, FIELD_MAIL_FROM_NAME); if (recordMailFromName != null) { finalMailFromName = recordMailFromName; } String recordMailBounceAddress = getStringField(record, FIELD_MAIL_BOUNCE_ADDRESS); if (recordMailBounceAddress != null) { finalMailBounceAddress = recordMailBounceAddress; } String recordMailReplyToAddress = getStringField(record, FIELD_MAIL_REPLYTO_ADDRESS); if (recordMailReplyToAddress != null) { finalMailReplyToAddress = recordMailReplyToAddress; } String recordMailSubject = getStringField(record, FIELD_MAIL_SUBJECT); if (recordMailSubject != null) { finalMailSubject = recordMailSubject; } String recordMailTo = getStringField(record, FIELD_MAIL_TO); if (recordMailTo != null) { finalMailTos = parseMailTo(recordMailTo); } } if (finalMailFromAddress == null) { record.addError(ProcessError.UNKNOWN_ERROR.getName(), "No From address defined"); failedRecords.add(record); continue; } if (finalMailBounceAddress == null) { record.addError(ProcessError.UNKNOWN_ERROR.getName(), "No Bounce address defined"); failedRecords.add(record); continue; } if (html || useTemplate) { if (html && useTemplate) { record.addError(ProcessError.UNKNOWN_ERROR.getName(), "Record has both " + FIELD_MAIL_USE_TEMPLATE + " and " + FIELD_MAIL_HTML + " fields. Only one of them is expected."); failedRecords.add(record); continue; } // HTML mail try { /** * Create and fill the mail */ ImageHtmlEmail htmlEmail = new ImageHtmlEmail(); // Set From info if (finalMailFromName != null) { htmlEmail.setFrom(finalMailFromAddress, finalMailFromName); } else { htmlEmail.setFrom(finalMailFromAddress); } htmlEmail.setBounceAddress(finalMailBounceAddress); if (finalMailReplyToAddress != null) { htmlEmail.addReplyTo(finalMailReplyToAddress); } htmlEmail.setSubject(finalMailSubject); // Allow to retrieve embedded images of the html template from the classpath (jar files) htmlEmail.setDataSourceResolver(new DataSourceClassPathResolver()); // Compute final HTML body from template and record fields String htmlBody = null; if (useTemplate) { htmlBody = createHtml(record); if (htmlBody == null) { // Error. Error message has already been set in createHtml: just add to failed record and // continue with next record failedRecords.add(record); continue; } } else { // html htmlBody = mailHtml; } htmlEmail.setHtmlMsg(htmlBody); // Add alternative text mail if any defined if (text) { htmlEmail.setTextMsg(mailText); } // Set To info if (finalMailTos.length == 0) { record.addError(ProcessError.UNKNOWN_ERROR.getName(), "No mail recipient."); failedRecords.add(record); continue; } for (String mailTo : finalMailTos) { htmlEmail.addTo(mailTo); } /** * Set sending parameters */ htmlEmail.setHostName(smtpServer); htmlEmail.setSmtpPort(smtpPort); if ((smtpSecurityUsername != null) && (smtpSecurityPassword != null)) { htmlEmail.setAuthentication(smtpSecurityUsername, smtpSecurityPassword); } htmlEmail.setSSLOnConnect(smtpSecuritySsl); // Send the mail htmlEmail.send(); } catch (EmailException ex) { record.addError(ProcessError.UNKNOWN_ERROR.getName(), "Unable to send email: " + ex.getMessage()); failedRecords.add(record); } } else { // Only text mail try { /** * Create and fill the mail */ SimpleEmail textEmail = new SimpleEmail(); // Set From info if (finalMailFromName != null) { textEmail.setFrom(finalMailFromAddress, finalMailFromName); } else { textEmail.setFrom(finalMailFromAddress); } textEmail.setBounceAddress(finalMailBounceAddress); if (finalMailReplyToAddress != null) { textEmail.addReplyTo(finalMailReplyToAddress); } textEmail.setSubject(finalMailSubject); textEmail.setMsg(mailText); // Set To info if (finalMailTos.length == 0) { record.addError(ProcessError.UNKNOWN_ERROR.getName(), "No mail recipient."); failedRecords.add(record); continue; } for (String mailTo : finalMailTos) { textEmail.addTo(mailTo); } /** * Set sending parameters */ textEmail.setHostName(smtpServer); textEmail.setSmtpPort(smtpPort); if ((smtpSecurityUsername != null) && (smtpSecurityPassword != null)) { textEmail.setAuthentication(smtpSecurityUsername, smtpSecurityPassword); } textEmail.setSSLOnConnect(smtpSecuritySsl); // Send the mail textEmail.send(); } catch (EmailException ex) { record.addError(ProcessError.UNKNOWN_ERROR.getName(), "Unable to send email: " + ex.getMessage()); failedRecords.add(record); } } } } if (debug) { logger.info("SendMail Processor records output: " + records); } return failedRecords; }
From source file:org.apache.isis.core.runtime.services.email.EmailServiceDefault.java
@Override public boolean send(final List<String> toList, final List<String> ccList, final List<String> bccList, final String subject, final String body, final DataSource... attachments) { try {/* ww w . ja v a 2 s . c o m*/ final ImageHtmlEmail email = new ImageHtmlEmail(); final String senderEmailAddress = getSenderEmailAddress(); final String senderEmailPassword = getSenderEmailPassword(); final String senderEmailHostName = getSenderEmailHostName(); final Integer senderEmailPort = getSenderEmailPort(); final Boolean senderEmailTlsEnabled = getSenderEmailTlsEnabled(); final int socketTimeout = getSocketTimeout(); final int socketConnectionTimeout = getSocketConnectionTimeout(); email.setAuthenticator(new DefaultAuthenticator(senderEmailAddress, senderEmailPassword)); email.setHostName(senderEmailHostName); email.setSmtpPort(senderEmailPort); email.setStartTLSEnabled(senderEmailTlsEnabled); email.setDataSourceResolver(new DataSourceClassPathResolver("/", true)); email.setSocketTimeout(socketTimeout); email.setSocketConnectionTimeout(socketConnectionTimeout); final Properties properties = email.getMailSession().getProperties(); properties.put("mail.smtps.auth", "true"); properties.put("mail.debug", "true"); properties.put("mail.smtps.port", "" + senderEmailPort); properties.put("mail.smtps.socketFactory.port", "" + senderEmailPort); properties.put("mail.smtps.socketFactory.class", "javax.net.ssl.SSLSocketFactory"); properties.put("mail.smtps.socketFactory.fallback", "false"); properties.put("mail.smtp.starttls.enable", "" + senderEmailTlsEnabled); email.setFrom(senderEmailAddress); email.setSubject(subject); email.setHtmlMsg(body); if (attachments != null && attachments.length > 0) { for (DataSource attachment : attachments) { email.attach(attachment, attachment.getName(), ""); } } final String overrideTo = getEmailOverrideTo(); final String overrideCc = getEmailOverrideCc(); final String overrideBcc = getEmailOverrideBcc(); final String[] toListElseOverride = actually(toList, overrideTo); if (notEmpty(toListElseOverride)) { email.addTo(toListElseOverride); } final String[] ccListElseOverride = actually(ccList, overrideCc); if (notEmpty(ccListElseOverride)) { email.addCc(ccListElseOverride); } final String[] bccListElseOverride = actually(bccList, overrideBcc); if (notEmpty(bccListElseOverride)) { email.addBcc(bccListElseOverride); } email.send(); } catch (EmailException ex) { LOG.error("An error occurred while trying to send an email", ex); final Boolean throwExceptionOnFail = isThrowExceptionOnFail(); if (throwExceptionOnFail) { throw new EmailServiceException(ex); } return false; } return true; }
From source file:org.apache.unomi.plugins.mail.actions.SendMailAction.java
public int execute(Action action, Event event) { String from = (String) action.getParameterValues().get("from"); String to = (String) action.getParameterValues().get("to"); String cc = (String) action.getParameterValues().get("cc"); String bcc = (String) action.getParameterValues().get("bcc"); String subject = (String) action.getParameterValues().get("subject"); String template = (String) action.getParameterValues().get("template"); ST stringTemplate = new ST(template); stringTemplate.add("profile", event.getProfile()); stringTemplate.add("event", event); // load your HTML email template String htmlEmailTemplate = stringTemplate.render(); // define you base URL to resolve relative resource locations try {/*from w ww. j a v a2 s . c o m*/ new URL("http://www.apache.org"); } catch (MalformedURLException e) { // } // create the email message HtmlEmail email = new ImageHtmlEmail(); // email.setDataSourceResolver(new DataSourceResolverImpl(url)); email.setHostName(mailServerHostName); email.setSmtpPort(mailServerPort); email.setAuthenticator(new DefaultAuthenticator(mailServerUsername, mailServerPassword)); email.setSSLOnConnect(mailServerSSLOnConnect); try { email.addTo(to); email.setFrom(from); if (cc != null && cc.length() > 0) { email.addCc(cc); } if (bcc != null && bcc.length() > 0) { email.addBcc(bcc); } email.setSubject(subject); // set the html message email.setHtmlMsg(htmlEmailTemplate); // set the alternative message email.setTextMsg("Your email client does not support HTML messages"); // send the email email.send(); } catch (EmailException e) { logger.error("Cannot send mail", e); } return EventService.NO_CHANGE; }
From source file:org.jooby.internal.mail.ImageHtmlEmailProvider.java
@Override public ImageHtmlEmail get() { return factory.newEmail(new ImageHtmlEmail()); }
From source file:rems.Global.java
public static boolean sendEmail(String toEml, String ccEml, String bccEml, String attchmnt, String sbjct, String bdyTxt, String[] errMsgs) { try {/*from w w w . ja v a 2s . co m*/ String selSql = "SELECT smtp_client, mail_user_name, mail_password, smtp_port FROM sec.sec_email_servers WHERE (is_default = 't')"; ResultSet selDtSt = Global.selectDataNoParams(selSql); selDtSt.last(); int m = selDtSt.getRow(); String smtpClnt = ""; String fromEmlNm = ""; String fromPswd = ""; errMsgs[0] = ""; int portNo = 0; if (m > 0) { selDtSt.beforeFirst(); selDtSt.next(); smtpClnt = selDtSt.getString(1); fromEmlNm = selDtSt.getString(2); fromPswd = selDtSt.getString(3); portNo = selDtSt.getInt(4); } selDtSt.close(); String fromPassword = Global.decrypt(fromPswd, Global.AppKey); // load your HTML email template if (bdyTxt.contains("<body") == false || bdyTxt.contains("</body>") == false) { bdyTxt = "<body>" + bdyTxt + "</body>"; } if (bdyTxt.contains("<html") == false || bdyTxt.contains("</html>") == false) { bdyTxt = "<!DOCTYPE html><html lang=\"en\">" + bdyTxt + "</html>"; } String htmlEmailTemplate = bdyTxt; // define you base URL to resolve relative resource locations URL url = new URL(Global.AppUrl); // create the email message ImageHtmlEmail email = new ImageHtmlEmail(); email.setDataSourceResolver(new DataSourceUrlResolver(url)); email.setHostName(smtpClnt); email.setSmtpPort(portNo); email.setAuthentication(fromEmlNm, fromPassword); email.setDebug(true); email.setStartTLSEnabled(true); email.setStartTLSRequired(true); String spltChars = "\\s*;\\s*"; String[] toEmails = removeDplctChars(toEml).trim().split(spltChars); String[] ccEmails = removeDplctChars(ccEml).trim().split(spltChars); String[] bccEmails = removeDplctChars(bccEml).trim().split(spltChars); String[] attchMnts = removeDplctChars(attchmnt).trim().split(spltChars); for (int i = 0; i < attchMnts.length; i++) { if (attchMnts[i].equals("")) { continue; } EmailAttachment attachment = new EmailAttachment(); if (attchMnts[i].startsWith("http://") || attchMnts[i].startsWith("https://")) { attachment.setURL(new URL(attchMnts[i].replaceAll(" ", "%20"))); //"http://www.apache.org/images/asf_logo_wide.gif" } else { attachment.setPath(attchMnts[i].replaceAll(" ", "%20")); } attachment.setDisposition(EmailAttachment.ATTACHMENT); //attachment.setDescription("Picture of John"); //attachment.setName("John"); // add the attachment email.attach(attachment); } int lovID = Global.getLovID("Email Addresses to Ignore"); int toMailsAdded = 0; for (int i = 0; i < toEmails.length; i++) { if (Global.isEmailValid(toEmails[i], lovID)) { if (Global.getEnbldPssblValID(toEmails[i], lovID) <= 0) { //DO Nothing toMailsAdded++; } else { toEmails[i] = "ToBeRemoved"; errMsgs[0] += "Address:" + toEmails[i] + " blacklisted by you!\r\n"; } } else { errMsgs[0] += "Address:" + toEmails[i] + " is Invalid!\r\n"; } } if (toMailsAdded <= 0) { return false; } for (int i = 0; i < toEmails.length; i++) { if (toEmails[i].equals("ToBeRemoved")) { toEmails = (String[]) ArrayUtils.remove(toEmails, i); } } if (toEmails.length > 0) { if (toEmails[0].equals("") == false) { email.addTo(toEmails); } } for (int i = 0; i < ccEmails.length; i++) { if (Global.isEmailValid(ccEmails[i], lovID)) { if (Global.getEnbldPssblValID(ccEmails[i], lovID) <= 0) { //DO Nothing } else { ccEmails[i] = "ToBeRemoved"; errMsgs[0] += "Address:" + ccEmails[i] + " blacklisted by you!\r\n"; } } else { errMsgs[0] += "Address:" + ccEmails[i] + " is Invalid!\r\n"; } } for (int i = 0; i < ccEmails.length; i++) { if (ccEmails[i].equals("ToBeRemoved")) { ccEmails = (String[]) ArrayUtils.remove(ccEmails, i); } } if (ccEmails.length > 0) { if (ccEmails[0].equals("") == false) { email.addCc(ccEmails); } } for (int i = 0; i < bccEmails.length; i++) { if (Global.isEmailValid(bccEmails[i], lovID)) { if (Global.getEnbldPssblValID(bccEmails[i], lovID) <= 0) { //DO Nothing } else { bccEmails[i] = "ToBeRemoved"; errMsgs[0] += "Address:" + bccEmails[i] + " blacklisted by you!\r\n"; } } else { errMsgs[0] += "Address:" + bccEmails[i] + " is Invalid!\r\n"; } } for (int i = 0; i < bccEmails.length; i++) { if (bccEmails[i].equals("ToBeRemoved")) { bccEmails = (String[]) ArrayUtils.remove(bccEmails, i); } } if (bccEmails.length > 0) { if (bccEmails[0].equals("") == false) { email.addBcc(bccEmails); } } email.setFrom(fromEmlNm.trim()); email.setSubject(sbjct); // set the html message email.setHtmlMsg(htmlEmailTemplate); // set the alternative message email.setTextMsg("Your email client does not support HTML messages"); // send the email if (Global.CheckForInternetConnection()) { email.send(); return true; } errMsgs[0] += "No Internet Connection"; return false; } catch (SQLException ex) { Global.errorLog = "\r\nFailed to send Email!\r\n" + ex.getMessage(); Global.writeToLog(); errMsgs[0] += "Failed to send Email!\r\n" + ex.getMessage(); return false; } catch (MalformedURLException ex) { Global.errorLog = "\r\nFailed to send Email!\r\n" + ex.getMessage(); Global.writeToLog(); errMsgs[0] += "Failed to send Email!\r\n" + ex.getMessage(); return false; } catch (EmailException ex) { Global.errorLog = "\r\nFailed to send Email!\r\n" + ex.getMessage(); Global.writeToLog(); errMsgs[0] += "Failed to send Email!\r\n" + ex.getMessage(); return false; } catch (Exception ex) { Global.errorLog = "\r\nFailed to send Email!\r\n" + ex.getMessage(); Global.writeToLog(); errMsgs[0] += "Failed to send Email!\r\n" + ex.getMessage(); return false; } }