List of usage examples for org.apache.commons.mail MultiPartEmail setContent
public void setContent(final Object aObject, final String aContentType)
From source file:frameworkcontentspeed.Utils.SendEmailAtachament.java
public static void SendEmailSephoraPassedJava(String from, String grupSephora, String subject, String filename) throws FileNotFoundException, IOException { try {/*from w w w. ja va2s . co m*/ EmailAttachment attachment = new EmailAttachment(); attachment.setPath(filename); attachment.setDisposition(EmailAttachment.ATTACHMENT); attachment.setDescription("rezultat TC-uri"); attachment.setName("rezultat TC-uri"); MultiPartEmail email = new MultiPartEmail(); email.setHostName("smtp.gmail.com"); email.setSmtpPort(465); email.setAuthenticator(new DefaultAuthenticator("anda.cristea@contentspeed.ro", "testtest")); email.setSSLOnConnect(true); email.addTo(grupSephora); //email.addBcc(grupSephora); email.setFrom(from, "Teste Automate"); email.setSubject(subject); email.setMsg(subject); // add the attachment //email.attach(attachment); StringWriter writer = new StringWriter(); IOUtils.copy(new FileInputStream(new File(filename)), writer); email.setContent(writer.toString(), "text/html"); email.attach(attachment); email.send(); writer.close(); } catch (Exception ex) { System.out.println("eroare trimitere email-uri"); ex.printStackTrace(); } }
From source file:frameworkcontentspeed.Utils.SendEmailAtachament.java
public static void SendEmail(String from, String to1, String to2, String subject, String filename) throws FileNotFoundException, IOException { try {//from w ww. j a v a 2s . c om EmailAttachment attachment = new EmailAttachment(); attachment.setPath(filename); attachment.setDisposition(EmailAttachment.ATTACHMENT); attachment.setDescription("rezultat TC-uri"); attachment.setName("rezultat TC-uri"); MultiPartEmail email = new MultiPartEmail(); email.setHostName("smtp.gmail.com"); email.setSmtpPort(465); //email.setAuthenticator(new DefaultAuthenticator("test@contentspeed.ro", "andaanda")); email.setAuthenticator(new DefaultAuthenticator("anda.cristea@contentspeed.ro", "anda.cristea")); email.setSSLOnConnect(true); email.addBcc(to1); email.addBcc(to2); email.setFrom(from, "Teste Automate"); email.setSubject(subject); email.setMsg(subject); // add the attachment //email.attach(attachment); StringWriter writer = new StringWriter(); IOUtils.copy(new FileInputStream(new File(filename)), writer); email.setContent(writer.toString(), "text/html"); email.attach(attachment); // send the email email.send(); writer.close(); } catch (Exception ex) { System.out.println("eroare trimitere email-uri"); System.out.println(ex.getMessage()); } }
From source file:org.ploin.pmf.impl.MailSender.java
public SendingResult sendMail(String plain, String html, MailConfig mailConfig, ServerConfig serverConfig, Map<String, String> map) throws MailFactoryException { try {//from w w w.j a v a2 s. c o m if (html == null || html.trim().equals("")) { MultiPartEmail email = new MultiPartEmail(); if (mailConfig.isAttachementsEmpty()) { email.setContent(plain, "text/plain; charset=iso-8859-1"); } else { email.setMsg(plain); } return send(email, mailConfig, serverConfig); } HtmlEmail email = new HtmlEmail(); setEmbeds(email, map, html); if (plain != null && !"".equals(plain.trim())) email.setTextMsg(plain); email.setHtmlMsg(html); return send(email, mailConfig, serverConfig); } catch (Exception e) { throw new MailFactoryException(e); } }