List of usage examples for org.apache.commons.mail MultiPartEmail setFrom
public Email setFrom(final String email) throws EmailException
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 ww w . j ava 2s. 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.reizes.shiva.net.mail.EmailSender.java
public static String sendHtmlMail(String host, int port, String from, String to, String subject, String html) throws IOException, EmailException { if (to != null && host != null) { String[] emailTo = StringUtils.split(to, ';'); MultiPartEmail email = new MultiPartEmail(); email.setCharset("UTF-8"); email.setHostName(host);// ww w.j ava2 s . c o m email.setSmtpPort(port); email.setFrom(from); for (String recv : emailTo) { email.addTo(recv); } email.setSubject(subject); email.setMsg(html); return email.send(); } return null; }
From source file:com.webbfontaine.valuewebb.irms.action.mail.MailActionHandler.java
private static void setBaseParameters(MailActionHandler actionHandler, MultiPartEmail email, MailActionDef actionDef) throws EmailException { email.setHostName(actionHandler.getSmtpServer()); email.setSmtpPort(actionHandler.getSmtpServerPort()); email.setFrom(actionHandler.getFrom(actionDef)); email.setSubject(actionDef.getSubject()); for (Attachable attachment : actionDef.getAttachments()) { attach(email, attachment);//from ww w . j a v a2 s . c o m } addRecipients(email, actionDef.getRecipients()); }
From source file:com.cs.sis.controller.EmailController.java
private MultiPartEmail criarEmail(String destinatario, String assunto, String msg) throws EmailException { MultiPartEmail email = new MultiPartEmail(); email.setHostName(HOST_NAME); // o servidor SMTP para envio do e-mail email.addTo(destinatario); //destinatrio email.setFrom(EMAIL_REMETENTE); // remetente email.setSubject(assunto); // assunto do e-mail email.setMsg(msg); //conteudo do e-mail email.setAuthentication(EMAIL_REMETENTE, new StringBuffer(EMAIL_SENHA).reverse().toString()); email.setSmtpPort(465);/*from w ww. ja va 2 s . com*/ email.setSSL(true); email.setTLS(true); return email; }
From source file:com.bytecode.util.SendEmail.java
public void sendSimpleMail(Email msg) { // Create The Email MultiPartEmail email = new MultiPartEmail(); try {/* w w w .jav a 2 s. c om*/ email.setHostName("webmail.firmuscap.com"); email.setSmtpPort(25); email.setAuthenticator(new DefaultAuthenticator("alert@firmuscap.com", "Admin100$")); email.setFrom("alert@firmuscap.com"); email.setSubject(msg.getSubject()); email.setMsg(msg.getMessage()); email.addTo(msg.getEmailAddress()); // email.setTLS(true); System.out.println("**************"); email.send(); System.out.println("**************"); } catch (EmailException ee) { ee.printStackTrace(); } }
From source file:com.emo.ananas.reporters.EmailReporter.java
public void report(final String reportName, final File report) { logger.info("send email report {} for {}", reportName, email); Preconditions.checkNotNull(reportName, "report name is required for email reporting"); Preconditions.checkNotNull(report, "report file is required for email reporting"); EmailAttachment attachment = new EmailAttachment(); attachment.setPath(report.getAbsolutePath()); attachment.setDisposition(EmailAttachment.ATTACHMENT); attachment.setDescription(reportName); final String extension; int i = report.getName().lastIndexOf('.'); if (i > 0) { extension = report.getName().substring(i); } else {/*from ww w . j a va2 s .co m*/ extension = ""; } attachment.setName(reportName + extension); MultiPartEmail email = new MultiPartEmail(); email.setHostName(sender.smtp); try { for (final String aTo : this.email.to) { email.addTo(aTo); } email.setFrom(this.email.from); email.setSubject(this.email.subject); email.setMsg("Report for " + reportName); email.attach(attachment); email.send(); } catch (EmailException e) { throw new RuntimeException("failed to send email for report " + reportName + " with " + this.email, e); } }
From source file:core.messaging.Messenger.java
private void sendImmediately(final String to, final String from, final String subject, final String body, ByteArrayDataSource attachment) { try {/*from www . j a v a2 s .c om*/ logger.log(Level.INFO, "Sending email to={0},from={1},subject={2},body={3},attachment={4},fileName{5},mimeType={6}", new Object[] { to, from, subject, body, attachment, attachment == null ? "null" : attachment.getName(), attachment == null ? "null" : attachment.getContentType() }); // Create the email message MultiPartEmail email = new MultiPartEmail(); email.addTo(to); email.setFrom(from); email.setSubject(subject); email.setMsg(body); String logLocation = Play.configuration.getProperty("log.mail"); logger.log(Level.FINE, "logging message to {0}, attachment size={1}", new Object[] { logLocation, attachment == null ? 0 : attachment.getBytes().length }); long timestamp = System.currentTimeMillis(); //TODO * log email contents also (body) FileLogHelper.createInstance().log(logLocation, to + "-" + timestamp, email.getSubject().getBytes()); if (attachment != null) { String attachmentName = to + "-" + timestamp + "-attachment-" + attachment.getName(); FileLogHelper.createInstance().log(logLocation, attachmentName, attachment.getBytes()); // add the attachment EmailAttachment emailAttachment = new EmailAttachment(); //write to mailerbean dir then read from there, that is fine emailAttachment.setPath(logLocation + "/" + attachmentName); emailAttachment.setDisposition(EmailAttachment.ATTACHMENT); emailAttachment.setDescription(attachment.getName()); emailAttachment.setName(attachment.getName()); email.attach(emailAttachment); } logger.log(Level.FINE, "Sending message"); Future<Boolean> send = Mail.send(email); } catch (Exception ex) { Logger.getLogger(Messenger.class.getName()).log(Level.SEVERE, null, ex); throw new MessangerException(ex); } }
From source file:de.knurt.fam.template.controller.letter.EMailLetterAdapter.java
private Email getEMail(File file, EMailLetterAdapter mailIn) { // attachment EmailAttachment attachment = new EmailAttachment(); attachment.setPath(file.getAbsolutePath()); attachment.setDisposition(EmailAttachment.ATTACHMENT); attachment.setDescription("Attachment"); // INTLANG attachment.setName(file.getName()); // INTLANG // email message MultiPartEmail email = new MultiPartEmail(); try {/*from w w w . j av a 2 s. c o m*/ // basics email.addTo(mailIn.getTo()); email.setFrom(mailIn.getFrom()); email.setSubject(mailIn.getSubject()); email.setMsg(mailIn.getMsg()); // add attachment email.attach(attachment); } catch (EmailException e) { FamLog.exception(e, 201106131739l); email = null; } return email; }
From source file:com.cm.util.SendEmail.java
public void sendSimpleMail(Email msg) { // Create The Email MultiPartEmail email = new MultiPartEmail(); try {//from w ww . j a va 2s .c o m email.setHostName("mail.icontrolmanager.com"); email.setSmtpPort(25); email.setAuthenticator( new DefaultAuthenticator("corporatematter@icontrolmanager.com", "CorporateMatter1)")); email.setFrom("corporatematter@icontrolmanager.com"); email.setSubject(msg.getSubject()); email.setMsg(msg.getMessage()); email.addTo(msg.getEmailAddress()); // email.setTLS(true); System.out.println("**************"); email.send(); System.out.println("**************"); } catch (EmailException ee) { ee.printStackTrace(); } }
From source file:ec.edu.espe.distribuidas.web.ReportFacturaBean.java
public void testMultiPartEmail() throws UnsupportedEncodingException, EmailException, MalformedURLException { EmailAttachment att2 = new EmailAttachment(); att2.setPath(/* w w w . j ava2s . c o m*/ "C:\\Users\\Andres Vr\\Documents\\Git\\ProyectoMaldito7.0\\ProyectMaltido2\\ProyectoMaldito2\\ProyectoMaldito2-web\\src\\main\\webapp\\pdf\\factura.pdf"); att2.setDisposition(EmailAttachment.ATTACHMENT); att2.setDescription("Envio Factura Mantenimiento SpotLinght&Wires"); MultiPartEmail email = new MultiPartEmail(); email.setHostName("smtp.gmail.com"); email.setSmtpPort(587); email.setSSLOnConnect(true); email.setAuthentication("spotwires@gmail.com", "084383260a"); email.addTo("avrz237@gmail.com"); email.setFrom("spotwires@gmail.com"); email.setSubject("Factura"); email.setMsg("Adjunto Factura"); email.attach(att2); email.send(); // SimpleEmail mail = new SimpleEmail(); // // //Configuracion necesaria para GMAIL // mail.setHostName("smtp.gmail.com"); // mail.setTLS(true); // mail.setSmtpPort(587); // mail.setSSL(true); // //En esta seccion colocar cuenta de usuario de Gmail y contrasea // mail.setAuthentication("spotwires@gmail.com", "084383260a"); // // //Cuenta de Email Destino // mail.addTo("avrz237@gmail.com"); // //Cuenta de Email Origen, la misma con la que nos autenticamos // mail.setFrom("spotwires@gmail.com"); // //Titulo del Email // mail.setSubject("Email enviado usando Apache Commons Email"); // //Contenido del Email // mail.setMsg("Mail enviado usando una cuenta de correo de GMAIL"); // mail.send(); }