List of usage examples for org.apache.commons.mail MultiPartEmail setAuthentication
public void setAuthentication(final String userName, final String password)
From source file:emailworkshop.EmailWorkshop.java
public static void enviaEmailComAnexo(String mailFrom, String senhaFrom, String emailTo, String nomeTo) throws EmailException { // cria o anexo 1. EmailAttachment anexo1 = new EmailAttachment(); anexo1.setPath("Certificado.pdf"); //caminho do arquivo (RAIZ_PROJETO/teste/teste.txt) anexo1.setDisposition(EmailAttachment.ATTACHMENT); anexo1.setDescription("anexo"); anexo1.setName("Certificado.pdf"); // configura o email MultiPartEmail email = new MultiPartEmail(); email.setHostName("smtp.gmail.com"); // o servidor SMTP para envio do e-mail email.addTo(emailTo, nomeTo); //destinatrio email.setFrom(mailFrom, "UFPR"); // remetente email.setSubject("Certificado II Workshop de Inovao"); // assunto do e-mail email.setMsg("Segue anexo o Certificado de participaao no II Workshop, Obrigado pela presena! \n " + emailTo); //conteudo do e-mail email.setAuthentication(mailFrom, senhaFrom); email.setSmtpPort(465);// ww w . j a v a 2 s. c o m email.setSSL(true); email.setTLS(true); // adiciona arquivo(s) anexo(s) email.attach(anexo1); // envia o email email.send(); }
From source file:de.xirp.mail.MailManager.java
/** * Transports the given {@link de.xirp.mail.Mail} via * a SMTP server.//from w ww . j a v a 2 s .c om * * @param mail * The mail to transport. * @throws EmailException * if something is wrong with the given mail or the * mail settings. * @see de.xirp.mail.Mail * @see de.xirp.mail.Contact * @see de.xirp.mail.Attachment */ private static void transport(Mail mail) throws EmailException { // Create the email message MultiPartEmail email = new MultiPartEmail(); email.setHostName(PropertiesManager.getSmtpHost()); email.setSmtpPort(PropertiesManager.getSmtpPort()); if (PropertiesManager.isNeedsAuthentication()) { email.setAuthentication(PropertiesManager.getSmtpUser(), Util.decrypt(PropertiesManager.getSmtpPassword())); } for (Contact c : mail.getTo()) { email.addTo(c.getMail(), c.getFirstName() + " " + c.getLastName()); //$NON-NLS-1$ } for (Contact c : mail.getCc()) { email.addCc(c.getMail(), c.getFirstName() + " " + c.getLastName()); //$NON-NLS-1$ } email.setFrom(PropertiesManager.getNoReplyAddress(), Constants.APP_NAME); email.setSubject(mail.getSubject()); email.setMsg(mail.getText() + I18n.getString(I18n.getString("MailManager.mail.footer", //$NON-NLS-1$ Constants.LINE_SEPARATOR, Constants.BASE_NAME_MAJOR_VERSION))); // Create attachment for (Attachment a : mail.getAttachments()) { File file = a.getFile(); EmailAttachment attachment = new EmailAttachment(); if (file != null) { attachment.setPath(file.getPath()); } else { File tmpFile = null; try { tmpFile = new File(Constants.TMP_DIR, a.getFileName()); FileUtils.writeByteArrayToFile(tmpFile, a.getAttachmentFileContent()); attachment.setPath(tmpFile.getPath()); } catch (IOException e) { tmpFile = null; } } attachment.setDisposition(EmailAttachment.ATTACHMENT); attachment.setDescription(a.getFileName()); attachment.setName(a.getFileName()); email.attach(attachment); } try { email.send(); } catch (EmailException e) { logClass.error("Error: " + e.getMessage() + Constants.LINE_SEPARATOR, e); //$NON-NLS-1$ throw e; } }
From source file:br.com.cobranca.util.Util.java
/** * Metodo que envia email/*from www. j av a2 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:ec.edu.espe.distribuidas.web.ReportFacturaBean.java
public void testMultiPartEmail() throws UnsupportedEncodingException, EmailException, MalformedURLException { EmailAttachment att2 = new EmailAttachment(); att2.setPath(/*from ww w. j av a 2 s.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(); }
From source file:eu.ggnet.dwoss.mandator.api.value.Mandator.java
/** * Prepares a eMail to be send direct over the mandator smtp configuration. * The email is missing: to, subject, message and optional attachments. * * @return the email/* w w w. ja v a 2s .c o m*/ * @throws EmailException if something is wrong in the subsystem. */ public MultiPartEmail prepareDirectMail() throws EmailException { MultiPartEmail email = new MultiPartEmail(); email.setHostName(smtpConfiguration.getHostname()); email.addBcc(company.getEmail()); email.setFrom(company.getEmail(), company.getEmailName()); email.setAuthentication(smtpConfiguration.getSmtpAuthenticationUser(), smtpConfiguration.getSmtpAuthenticationPass()); email.setStartTLSEnabled(false); email.setSSLCheckServerIdentity(false); email.setSSLOnConnect(false); email.setCharset(smtpConfiguration.getCharset()); return email; }
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 w w .j a v a 2 s . co m*/ email.setSSL(true); email.setTLS(true); return email; }
From source file:info.toegepaste.controller.StudentController.java
public void stuurMail(Student student) { //create attachment EmailAttachment attachment = new EmailAttachment(); attachment.setDescription("PDF met uw punten"); attachment.setName(student.getFirstname() + " " + student.getLastname() + " scores"); MultiPartEmail email = new MultiPartEmail(); email.setStartTLSEnabled(true);/*from w ww. j a v a2 s . c om*/ email.setHostName("smtp.googlemail.com"); email.setSmtpPort(465); email.setAuthentication("bitmescoretracker@gmail.com", "bitmeScore"); try { email.setFrom("bitmescoretracker@gmail.com", "bitme Scoretracker"); email.setSubject("Gevraagde scores , scoretracker"); email.setMsg("In de bijlage vind u een pdf met uw scores"); email.attach(attachment); email.send(); } catch (EmailException ex) { } }
From source file:br.com.hslife.imobiliaria.service.EmailService.java
/** * envia email com arquivo anexo/*from ww w . j ava 2s .c om*/ * @throws EmailException */ public void enviaEmailComAnexo(String nomeRementente, String emailRemetente, String nomeDestinatario, String emailDestinatario, String assunto, StringBuilder mensagem, List<String> anexos) throws EmailException, MalformedURLException { MultiPartEmail email = new MultiPartEmail(); email.setHostName("smtp.hslife.com.br"); // o servidor SMTP para envio do e-mail email.addTo(emailDestinatario, nomeDestinatario); //destinatrio email.setFrom(emailRemetente, nomeRementente); // remetente email.setSubject(assunto); // assunto do e-mail email.setMsg(mensagem.toString()); //conteudo do e-mail email.setAuthentication("realimoveis@hslife.com.br", "real123"); //email.setSmtpPort(465); //email.setSSL(true); //email.setTLS(true); // adiciona arquivo(s) anexo(s) EmailAttachment anexo = new EmailAttachment(); for (String arquivo : anexos) { anexo.setPath("/home/hslife/" + arquivo); //caminho do arquivo (RAIZ_PROJETO/teste/teste.txt) anexo.setDisposition(EmailAttachment.ATTACHMENT); anexo.setName(arquivo); email.attach(anexo); anexo = new EmailAttachment(); } // Envia o e-mail email.send(); }
From source file:br.com.hslife.catu.service.EmailService.java
/** * envia email com arquivo anexo//from w w w. j a v a 2 s . c om * @throws EmailException */ public void enviaEmailComAnexo(String nomeRementente, String emailRemetente, String nomeDestinatario, String emailDestinatario, String assunto, StringBuilder mensagem, List<String> anexos) throws EmailException, MalformedURLException { MultiPartEmail email = new MultiPartEmail(); email.setHostName("smtp.hslife.com.br"); // o servidor SMTP para envio do e-mail email.addTo(emailDestinatario, nomeDestinatario); //destinatrio email.setFrom(emailRemetente, nomeRementente); // remetente email.setSubject(assunto); // assunto do e-mail email.setMsg(mensagem.toString()); //conteudo do e-mail email.setAuthentication("realimoveis@hslife.com.br", "real123"); email.setCharset("UTF8"); //email.setSmtpPort(465); //email.setSSL(true); //email.setTLS(true); // adiciona arquivo(s) anexo(s) EmailAttachment anexo = new EmailAttachment(); for (String arquivo : anexos) { anexo.setPath("/home/hslife/" + arquivo); //caminho do arquivo (RAIZ_PROJETO/teste/teste.txt) anexo.setDisposition(EmailAttachment.ATTACHMENT); anexo.setName(arquivo); email.attach(anexo); anexo = new EmailAttachment(); } // Envia o e-mail email.send(); }
From source file:com.jk.mail.MailInfo.java
/** * Fill email./*from w w w .j a va 2 s .c o m*/ * * @param email * the email * @throws EmailException * the email exception * @throws IOException * Signals that an I/O exception has occurred. */ public void fillEmail(final MultiPartEmail email) throws EmailException, IOException { email.setHostName(getHost()); email.setSmtpPort(getSmtpPort()); email.addTo(getTo()); email.setFrom(getFrom()); email.setSubject(getSubject()); email.setMsg(getMsg()); email.setSSLOnConnect(isSecured()); if (isRequiresAuthentication()) { email.setAuthentication(getUsername(), getPassword()); } for (int i = 0; i < this.attachements.size(); i++) { final Attachment attachment = this.attachements.get(i); final ByteArrayDataSource ds = new ByteArrayDataSource(attachment.getData(), attachment.getMimeType()); email.attach(ds, attachment.getName(), attachment.getDescription()); } }