List of usage examples for org.apache.commons.mail MultiPartEmail setDebug
public void setDebug(final boolean d)
From source file:com.zuora.api.UsageAdjInvoiceRegenerator.java
public static void main(String[] args) { String exportIdPRPC, exportIdII, exportFileIdII, exportFileIdPRPC, queryII, queryPRPC; boolean hasArgs = false; if (args != null && args.length >= 1) { UsageAdjInvoiceRegenerator.PROPERTY_FILE_NAME = args[0]; hasArgs = true;//from w ww .ja v a 2 s. c o m } AppParamManager.initParameters(hasArgs); if (!AppParamManager.TASK_ID.equals("")) { try { zApiClient = new ApiClient(AppParamManager.API_URL, AppParamManager.USER_NAME, AppParamManager.USER_PASSWORD, AppParamManager.USER_SESSION); zApiClient.login(); } catch (Exception ex) { Logger.print(ex); Logger.print("RefreshSession - There's exception in the API call."); } queryPRPC = AppParamManager.PRPCexportQuery; queryII = AppParamManager.IIexportQuery; exportIdPRPC = zApiClient.createExport(queryPRPC); exportIdII = zApiClient.createExport(queryII); // ERROR createExport fails if (exportIdII == null || exportIdII.equals("")) { Logger.print("Error. Failed to create Invoice Item Export"); //return false; } // ERROR createExport fails if (exportIdPRPC == null || exportIdPRPC.equals("")) { Logger.print("Error. Failed to create PRPC export"); //return false; } exportFileIdII = zApiClient.getExportFileId(exportIdII); if (exportFileIdII == null) { Logger.print("Error. Failed to get Invoice Item Export file Id"); //log.closeLogFile(); //return false; } exportFileIdPRPC = zApiClient.getExportFileId(exportIdPRPC); if (exportFileIdPRPC == null) { Logger.print("Error. Failed to get PRPC Export file Id"); //log.closeLogFile(); //return false; } // get the export file from zuora //zApiClient.getFile(exportFileIdII, exportFileIdTI); /* Logger.print("II export ID: "+exportFileIdII); Logger.print("TI export ID: "+exportFileIdTI); */ Logger.print("Opening Export file"); //Base64 bs64 = new BASE64Encoder(); /* String login = AppParamManager.USER_NAME+":"+AppParamManager.USER_PASSWORD; String authorization ="Basic "+ Base64.encodeBase64String(login.getBytes()); String zendpoint = ""; */ String authorization = ""; //Base64 bs64 = new BASE64Encoder(); if (AppParamManager.USER_SESSION.isEmpty()) { String login = AppParamManager.USER_NAME + ":" + AppParamManager.USER_PASSWORD; authorization = "Basic " + Base64.encodeBase64String(login.getBytes()); } else { authorization = "ZSession " + AppParamManager.USER_SESSION; } String zendpoint = ""; try { /* if( AppParamManager.API_URL.contains("api") ){ //look in api sandbox zendpoint = "https://apisandbox.zuora.com/apps/api/file/"; } else { //look in production zendpoint = "https://www.zuora.com/apps/api/file/"; } */ int index = AppParamManager.API_URL.indexOf("apps"); index = index + 5; zendpoint = AppParamManager.API_URL.substring(0, index) + "api/file/"; Logger.print(zendpoint); //zendpoint = AppParamManager.FILE_URL; //Start reading Invoice Items String zendpointII = zendpoint + exportFileIdII + "/"; URL url = new URL(zendpointII); URLConnection uc = url.openConnection(); //Logger.print("Opening invoice item file: "+exportFileIdII+" authorization: "+authorization); uc.setRequestProperty("Authorization", authorization); InputStream content = (InputStream) uc.getInputStream(); BufferedReader in = new BufferedReader(new InputStreamReader(content)); CSVReader cvsReader = new CSVReader(in); List<String[]> batchOfRawDataList = null; while ((batchOfRawDataList = cvsReader.parseEntity()) != null) { UsageAdjInvoiceRegenerator.readInvoices(batchOfRawDataList, cvsReader.getBatchStartLineNumber(), "InvoiceItem"); } in.close(); String zenpointPRPC = zendpoint + exportFileIdPRPC + "/"; url = new URL(zenpointPRPC); uc = url.openConnection(); uc.setRequestProperty("Authorization", authorization); content = (InputStream) uc.getInputStream(); in = new BufferedReader(new InputStreamReader(content)); cvsReader = new CSVReader(in); while ((batchOfRawDataList = cvsReader.parseEntity()) != null) { UsageAdjInvoiceRegenerator.readInvoices(batchOfRawDataList, cvsReader.getBatchStartLineNumber(), "PRPCItem"); } in.close(); Logger.print("start processing values"); UsageAdjInvoiceRegenerator chargeAdjustment = new UsageAdjInvoiceRegenerator(); int[] results; int totalErrors = 0; String emailmsg = ""; Logger.print("----------------------------------------"); Logger.print("start creating usages"); results = zApiClient.createUsageItems(newUsageCollection); if (results[1] != 0) { emailmsg = (results[0] - results[1]) + "/" + results[0] + " usage creation "; } totalErrors = totalErrors + results[1]; Logger.print("start cancelling invoices"); results = zApiClient.alterInvoices(newUsageCollection, "cancel"); if (results[1] != 0) { emailmsg = (results[0] - results[1]) + "/" + results[0] + " invoice cancellation "; } totalErrors = totalErrors + results[1]; Logger.print("start deleting usages"); results = zApiClient.deleteUsageItems(deleteList); if (results[1] != 0) { emailmsg = (results[0] - results[1]) + "/" + results[0] + " usage deletion "; } totalErrors = totalErrors + results[1]; Logger.print("start regenerating invoices"); results = zApiClient.alterInvoices(newUsageCollection, "generate"); if (results[1] != 0) { emailmsg = (results[0] - results[1]) + "/" + results[0] + " invoice generation "; } totalErrors = totalErrors + results[1]; Logger.print("start deleting old invoices"); results = zApiClient.alterInvoices(newUsageCollection, "delete"); if (results[1] != 0) { emailmsg = (results[0] - results[1]) + "/" + results[0] + " invoice deletion "; } totalErrors = totalErrors + results[1]; // Create the attachment EmailAttachment attachment = new EmailAttachment(); if (totalErrors > 0) { String logFileName = AppParamManager.OUTPUT_FOLDER_LOCATION + File.separator + "runtime_log_" + AppParamManager.OUTPUT_FILE_POSTFIX + ".txt"; attachment.setPath(logFileName); attachment.setDisposition(EmailAttachment.ATTACHMENT); attachment.setDescription("System Log"); attachment.setName("System Log"); } MultiPartEmail email = new MultiPartEmail(); email.setSmtpPort(587); email.setAuthenticator( new DefaultAuthenticator(AppParamManager.EMAIL_ADDRESS, AppParamManager.EMAIL_PASSWORD)); email.setDebug(false); email.setHostName("smtp.gmail.com"); email.setFrom("zuora@gmail.com"); if (totalErrors > 0) { email.setSubject("Base Calc Processor Finished with Errors"); email.setMsg("The base calc processing has finished " + emailmsg + "records successfully."); } else { email.setSubject("Base Calc Processor Finished Successfully"); emailmsg = (results[0] - results[1]) + "/" + results[0] + " invoice "; email.setMsg("The base calc processing has finished " + emailmsg + "records successfully."); } email.setTLS(true); email.addTo(AppParamManager.RECIPIENT_ADDRESS); if (totalErrors > 0) { email.attach(attachment); } email.send(); System.out.println("Mail sent!"); if (hasArgs) { Connection conn = AppParamManager.getConnection(); Statement stmt = conn.createStatement(); DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); java.util.Date date = new Date(); stmt.executeUpdate("UPDATE TASK SET STATUS = 'completed', END_TIME = '" + dateFormat.format(date) + "' WHERE ID = " + AppParamManager.TASK_ID); Utility.saveLogToDB(conn); conn.close(); } } catch (Exception e) { Logger.print("Failure, gettingFile."); Logger.print("Error getting the export file: " + e.getMessage()); //System.out.println("Error getting the export file: "+e.getMessage()); try { Connection conn = AppParamManager.getConnection(); Statement stmt = conn.createStatement(); DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); java.util.Date date = new Date(); stmt.executeUpdate("UPDATE TASK SET STATUS = 'failed', END_TIME = '" + dateFormat.format(date) + "' WHERE ID = " + AppParamManager.TASK_ID); Utility.saveLogToDB(conn); conn.close(); } catch (Exception e2) { // TODO Auto-generated catch block e2.printStackTrace(); } } } else { Logger.print("No tasks in wait status"); } }
From source file:com.github.somi92.seecsk.util.email.EmailSender.java
public static void sendEmail(EmailContainer ec) throws RuntimeException { try {/*from w w w .ja va 2 s . c o m*/ String user = Config.vratiInstancu().vratiVrednost(Constants.OrgInfoConfigKeys.ORGANISATION_EMAIL); String password = Config.vratiInstancu() .vratiVrednost(Constants.OrgInfoConfigKeys.ORGANISATION_EMAIL_PASSWORD); EmailAttachment ea = new EmailAttachment(); ea.setPath(ec.getAttachmentPath()); ea.setDisposition(EmailAttachment.ATTACHMENT); ea.setDescription("Primer ispravno popunjene uplatnice za ?lanarinu"); ea.setName("uplatnica.pdf"); MultiPartEmail mpe = new MultiPartEmail(); mpe.setDebug(true); mpe.setAuthenticator(new DefaultAuthenticator(user, password)); mpe.setHostName( Config.vratiInstancu().vratiVrednost(Constants.EmailServerConfigKeys.EMAIL_SERVER_HOST)); mpe.setSSLOnConnect(true); mpe.setStartTLSEnabled(true); mpe.setSslSmtpPort( Config.vratiInstancu().vratiVrednost(Constants.EmailServerConfigKeys.EMAIL_SERVER_PORT)); mpe.setSubject(ec.getSubject()); mpe.setFrom(ec.getFromEmail(), Config.vratiInstancu().vratiVrednost(Constants.OrgInfoConfigKeys.ORGANISATION_NAME)); mpe.setMsg(ec.getMessage()); mpe.addTo(ec.getToEmail()); mpe.attach(ea); mpe.send(); } catch (EmailException ex) { ex.printStackTrace(); throw new RuntimeException("Sistem nije uspeo da poalje email. Pokuajte ponovo."); } }
From source file:br.com.cobranca.util.Util.java
/** * Metodo que envia email//from ww w. jav a 2 s .c o m * * @param divida * @param boleto */ public static void enviarEmail(Divida divida, String boleto) { MultiPartEmail emailTemp = new MultiPartEmail(); try { emailTemp.setDebug(true); emailTemp.setHostName("smtp.gmail.com"); emailTemp.setSmtpPort(587); emailTemp.setStartTLSEnabled(true); emailTemp.setAuthentication("homework.fca@gmail.com", "homework@"); emailTemp.setFrom("syscob@sycob.com.br", "SYSCOB"); emailTemp.addTo(divida.getDevedor().getEmail()); emailTemp.setSubject("Boleto - Syscob "); emailTemp.setMsg("Ol, " + divida.getDevedor().getNome() + "\n" + "Segue anexo Boleto referente a negociao de cdigo: " + divida.getId() + "\n\n" + "Obs: Favor confirmar o recebimento deste. \n\n\n\n" + "Att \n" + "Syscob"); boleto = boleto.replace("/", File.separator); File f = new File(boleto); EmailAttachment attachment = new EmailAttachment(); attachment.setPath(f.getPath()); attachment.setDisposition(EmailAttachment.ATTACHMENT); attachment.setName(f.getName()); emailTemp.attach(attachment); emailTemp.send(); } catch (Exception e) { System.out.println("Erro: " + e.getMessage()); } finally { } }
From source file:binky.reportrunner.engine.utils.impl.EmailHandlerImpl.java
public void sendEmail(String destinationEmail, String fromEmail, String smtpServer, String fileUrl, String jobName, String groupName) throws EmailException, IOException { logger.debug("sending email to: " + destinationEmail + " on host " + smtpServer); FileSystemHandler fs = new FileSystemHandlerImpl(); MultiPartEmail email = new MultiPartEmail(); email.setDebug(debug); email.setHostName(smtpServer);//from w w w . java 2s.c o m for (String toEmail : destinationEmail.split(",")) { email.addTo(toEmail.trim()); } email.setFrom(fromEmail); email.setSubject(subject + jobName + " [" + groupName + "]"); email.setMsg(message); List<String> tempFiles = new LinkedList<String>(); EmailAttachment attachment = new EmailAttachment(); String temp = copyToTemp(fileUrl); tempFiles.add(temp); attachment.setURL(fs.getURL(temp)); attachment.setDisposition(EmailAttachment.ATTACHMENT); attachment.setDescription("Report Runner Report"); // get the file name of the report from the complete path String name = fs.getFileName(fileUrl); attachment.setName(name); logger.debug("File: " + fileUrl); logger.debug("Name: " + name); email.attach(attachment); email.send(); fs.deleteFile(temp); }
From source file:binky.reportrunner.engine.utils.impl.EmailHandlerImpl.java
public void sendEmail(String destinationEmail, String fromEmail, String smtpServer, List<String> fileUrls, String jobName, String groupName) throws EmailException, IOException { // logger.debug("sending email to: " + to + " on host " + server); FileSystemHandler fs = new FileSystemHandlerImpl(); MultiPartEmail email = new MultiPartEmail(); email.setDebug(debug); email.setHostName(smtpServer);/*from w w w . ja v a2 s. c o m*/ for (String toEmail : destinationEmail.split(",")) { email.addTo(toEmail.trim()); } email.setFrom(fromEmail); email.setSubject(subject + jobName + " [" + groupName + "]"); email.setMsg("Please find attached outputs for the above job."); List<String> tempFiles = new LinkedList<String>(); for (String url : fileUrls) { EmailAttachment attachment = new EmailAttachment(); String temp = copyToTemp(url); tempFiles.add(temp); attachment.setURL(fs.getURL(temp)); attachment.setDisposition(EmailAttachment.ATTACHMENT); attachment.setDescription(message); // get the file name of the report from the complete path String name = fs.getFileName(url); attachment.setName(name); logger.debug("File: " + url); logger.debug("Name: " + name); email.attach(attachment); } email.send(); for (String url : tempFiles) { fs.deleteFile(url); } }
From source file:com.dominion.salud.pedicom.negocio.tools.MAILTest.java
@Ignore @Test/*from w ww . j a v a 2 s . c o m*/ public void send() { try { MultiPartEmail email = new MultiPartEmail(); email.setHostName(SMTP); email.setAuthenticator(new DefaultAuthenticator(USUARIO, PASSWORD)); email.setDebug(true); email.setSmtpPort(PUERTO); email.setStartTLSEnabled(true); email.setSSLOnConnect(true); email.setFrom(FROM, FROM); email.addTo(TO, TO); email.setSubject("Correo de Prueba"); email.attach(new File("/home/jcgonzalez/TMP/a.hl7")); email.send(); } catch (Exception e) { logger.error(e.toString()); } }
From source file:binky.reportrunner.engine.utils.impl.EmailHandlerImpl.java
public void sendAlertEmail(String destinationEmail, String fromEmail, String smtpServer, String jobName, String groupName, boolean success, Date finishTime) throws EmailException, IOException { logger.debug("sending email to: " + destinationEmail + " on host " + smtpServer); MultiPartEmail email = new MultiPartEmail(); email.setHostName(smtpServer);//from w w w.j a v a 2s. c o m email.setDebug(debug); for (String toEmail : destinationEmail.split(",")) { email.addTo(toEmail.trim()); } email.setFrom(fromEmail); if (success) { email.setSubject("Success message for: " + jobName + " [" + groupName + "]"); email.setMsg("Job completed successfully at " + finishTime); } else { email.setSubject("Failure message for: " + jobName + " [" + groupName + "]"); email.setMsg("Job completed with error(s) at " + finishTime); } email.send(); }
From source file:TestSendMail.java
public void testSend() { try {/*from w w w. j a v a2 s . co m*/ Security.removeProvider(new BouncyCastleProvider().getName()); Security.addProvider(new BouncyCastleProvider()); //log.info("Lista de proveedores disponible:"+Arrays.asList(Security.getProviders())); org.apache.xml.security.Init.init(); Properties configuracion = new Properties(); configuracion.put("HOST_SMTP", "192.168.10.7"); SendMailUtil.init(configuracion); //benito.galan@avansi.com.do MultiPartEmail mail = SendMailUtil.getCurrentInstance().buildMessage("Ejemplo de Firma", "rquintero@viavansi.com", "", "<p>rubén</p> ", "certificadoavansicxa", "avansicxa"); mail.setDebug(true); // Enviamos String id = mail.send(); System.out.println(id); mail.getMimeMessage().writeTo(System.out); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:com.teamj.distribuidas.web.EmailSessionBean.java
public void sendEmail(String to, String subject, String body, String path) { //Email email = new SimpleEmail(); MultiPartEmail email = new MultiPartEmail(); email.setHostName("smtp.gmail.com"); email.setSmtpPort(587);// www .j a v a 2s .co m email.setAuthenticator(new DefaultAuthenticator("dennysaurio", "tuclave")); // email.setSSLOnConnect(true); email.setDebug(true); //email.setStartTLSEnabled(true); try { email.getMailSession().getProperties().put("mail.smtps.auth", "true"); email.getMailSession().getProperties().put("mail.debug", "true"); email.getMailSession().getProperties().put("mail.smtps.port", "587"); email.getMailSession().getProperties().put("mail.smtps.socketFactory.port", "587"); email.getMailSession().getProperties().put("mail.smtps.socketFactory.class", "javax.net.ssl.SSLSocketFactory"); email.getMailSession().getProperties().put("mail.smtps.socketFactory.fallback", "false"); email.getMailSession().getProperties().put("mail.smtp.starttls.enable", "true"); email.getMailSession().getProperties().put("mail.smtp.ssl.trust", "smtp.gmail.com"); EmailAttachment attachment = new EmailAttachment(); // #{facesContext.externalContext.requestContextPath} attachment.setPath("D:\\IMG_20151101_213514644.jpg"); attachment.setDisposition(EmailAttachment.ATTACHMENT); attachment.setDescription("Picture of Anita"); attachment.setName("anita.jpg"); //email.setTLS(true); /** * smtp.host=smtp.gmail.com smtp.port=587 smtp.ssl=yes * props.put("mail.smtp.starttls.enable", "true"); * props.put("mail.smtp.auth", "true"); smtp.user="me@gmail.com" * smtp.password="myPassword" */ email.setFrom("dennysaurio@gmail.com"); email.setSubject(subject); email.setMsg(body); email.addTo(to); email.attach(attachment); email.send(); } catch (EmailException ex) { Logger.getLogger(EmailSessionBean.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.client.named.RegisterPrestario.java
public void sendEmail(String senderId, String subject, String body) throws UnsupportedEncodingException, MessagingException { String myEmailId = "computo.citecvlp@gmail.com"; String myPassword = "impresora73"; try {//from w w w . j a v a 2 s .c o m MultiPartEmail email = new MultiPartEmail(); email.setSmtpPort(587); email.setAuthenticator(new DefaultAuthenticator(myEmailId, myPassword)); email.setDebug(true); email.setHostName("smtp.gmail.com"); email.setFrom(myEmailId); email.setSubject("activacion cuenta laboratorio computo UABC"); email.setMsg(body); email.addTo(senderId); email.setTLS(true); /* EmailAttachment attachment = new EmailAttachment(); attachment.setPath("/Users/fahadparkar/Desktop/Fahim/tables.xlsx"); attachment.setDisposition(EmailAttachment.ATTACHMENT); attachment.setDescription("Excel"); attachment.setName("tables.xlsx"); email.attach(attachment);*/ email.send(); System.out.println("Mail sent!"); } catch (EmailException e) { System.out.println("Exception :: " + e); } }