List of usage examples for org.apache.commons.mail HtmlEmail HtmlEmail
HtmlEmail
From source file:br.vn.Model.Filtros.Email.java
public void enviarHatml(String emailcliente) throws MalformedURLException { try {// w w w . j a v a2s . co m // Criar a mensagem de e-mail HtmlEmail email = new HtmlEmail(); email.setHostName("org.apache.commons"); email.addTo("jdoe@somewhere.org", "John Doe"); email.setFrom("me@apache.org", "Me"); email.setSubject("Test email with inline image"); //incorporar a imagem e obter o ID de contedo URL url = new URL("http://www.apache.org/images/asf_logo_wide.gif"); String cid = email.embed(url, "Apache logo"); // definir a mensagem HTML email.setHtmlMsg("<html>The apache logo - <img src=\"cid:" + cid + "\"></html>"); // definir a mensagem alternativa email.setTextMsg("Your email client does not support HTML messages"); // enviar o e-mail email.send(); } catch (EmailException ex) { Logger.getLogger(Email.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.baifendian.swordfish.common.mail.MailSendUtil.java
/** * ??/*from ww w . j a v a 2 s . com*/ * * @param receivers * @param title * @param content * @return */ public static boolean sendMails(Collection<String> receivers, String title, String content) { if (receivers == null) { LOGGER.error("Mail receivers is null."); return false; } receivers.removeIf((from) -> (StringUtils.isEmpty(from))); if (receivers.isEmpty()) { LOGGER.error("Mail receivers is empty."); return false; } // ?? email HtmlEmail email = new HtmlEmail(); try { // SMTP ?????, 163 "smtp.163.com" email.setHostName(mailServerHost); email.setSmtpPort(mailServerPort); // ? email.setCharset("UTF-8"); // for (String receiver : receivers) { email.addTo(receiver); } // ?? email.setFrom(mailSender, mailSender); // ???????-?????? email.setAuthentication(mailSender, mailPasswd); // ??? email.setSubject(title); // ???? HtmlEmail? HTML email.setMsg(content); // ?? email.send(); return true; } catch (Throwable e) { LOGGER.error("Send email to {} failed", StringUtils.join(",", receivers), e); } return false; }
From source file:com.kylinolap.job.tools.MailService.java
public void sendMail(List<String> receivers, String subject, String content) throws IOException { Email email = new HtmlEmail(); email.setHostName(host);/* w w w. j a va 2 s . c om*/ email.setDebug(true); try { for (String receiver : receivers) { email.addTo(receiver); } email.setFrom(sender); email.setSubject(subject); email.setCharset("UTF-8"); ((HtmlEmail) email).setHtmlMsg(content); email.send(); email.getMailSession(); System.out.println("!!"); } catch (EmailException e) { e.printStackTrace(); } }
From source file:ca.ualberta.physics.cssdp.auth.service.EmailServiceImpl.java
public void sendEmail(String from, String to, String subject, String body) { try {/*from w w w . j a v a 2 s . c o m*/ String host = AuthServer.properties().getString("smtpHost"); int port = AuthServer.properties().getInt("smtpPort"); final String user = AuthServer.properties().getString("smtpUsername"); final String password = AuthServer.properties().getString("smtpPassword"); String systemEmail = AuthServer.properties().getString("systemEmailAddress"); boolean useSSL = AuthServer.properties().getBoolean("smtpUseSSL"); boolean debug = AuthServer.properties().getBoolean("smtpDebug"); HtmlEmail msg = new HtmlEmail(); msg.setHostName(host); msg.setAuthentication(user, password); msg.setSmtpPort(port); msg.setSSL(useSSL); msg.setDebug(debug); msg.setSubject("Password Reset Request"); msg.addTo(to); msg.setFrom(systemEmail); msg.setHtmlMsg(body); msg.send(); } catch (Exception e) { e.printStackTrace(); throw Throwables.propagate(Throwables.getRootCause(e)); } finally { } }
From source file:com.mycollab.module.mail.DefaultMailer.java
private HtmlEmail getBasicEmail(String fromEmail, String fromName, List<MailRecipientField> toEmail, List<MailRecipientField> ccEmail, List<MailRecipientField> bccEmail, String subject, String html) { try {//from w ww . jav a 2s. c o m HtmlEmail email = new HtmlEmail(); email.setHostName(emailConf.getHost()); email.setSmtpPort(emailConf.getPort()); email.setStartTLSEnabled(emailConf.getIsStartTls()); email.setSSLOnConnect(emailConf.getIsSsl()); email.setFrom(fromEmail, fromName); email.setCharset(EmailConstants.UTF_8); for (MailRecipientField aToEmail : toEmail) { if (isValidate(aToEmail.getEmail()) && isValidate(aToEmail.getName())) { email.addTo(aToEmail.getEmail(), aToEmail.getName()); } else { LOG.error(String.format("Invalid to email input: %s---%s", aToEmail.getEmail(), aToEmail.getName())); } } if (CollectionUtils.isNotEmpty(ccEmail)) { for (MailRecipientField aCcEmail : ccEmail) { if (isValidate(aCcEmail.getEmail()) && isValidate(aCcEmail.getName())) { email.addCc(aCcEmail.getEmail(), aCcEmail.getName()); } else { LOG.error(String.format("Invalid cc email input: %s---%s", aCcEmail.getEmail(), aCcEmail.getName())); } } } if (CollectionUtils.isNotEmpty(bccEmail)) { for (MailRecipientField aBccEmail : bccEmail) { if (isValidate(aBccEmail.getEmail()) && isValidate(aBccEmail.getName())) { email.addBcc(aBccEmail.getEmail(), aBccEmail.getName()); } else { LOG.error(String.format("Invalid bcc email input: %s---%s", aBccEmail.getEmail(), aBccEmail.getName())); } } } if (emailConf.getUser() != null) { email.setAuthentication(emailConf.getUser(), emailConf.getPassword()); } email.setSubject(subject); if (StringUtils.isNotBlank(html)) { email.setHtmlMsg(html); } return email; } catch (EmailException e) { throw new MyCollabException(e); } }
From source file:com.cerebro.gorgone.commons.SendConfEmail.java
public SendConfEmail(String address, String confCode) { logger.info("Invio della mail di conferma"); // Leggo i parametri di invio Properties props = new Properties(); InputStream config = VaadinServlet.getCurrent().getServletContext() .getResourceAsStream("/WEB-INF/config.properties"); if (config != null) { try {//from ww w . j a v a2s .c o m logger.info("Carico il file .properties"); props.load(config); } catch (Exception ex) { logger.error("Errore nel caricamento del file .properties: " + ex.getMessage()); } } smtp_host = props.getProperty(ConfigProperties.SMTP_HOST); smtp_port = Integer.getInteger(props.getProperty(ConfigProperties.SMTP_PORT)); smtp_user = props.getProperty(ConfigProperties.SMTP_USER); smtp_pwd = props.getProperty(ConfigProperties.SMTP_PWD); smtp_security = Boolean.parseBoolean(ConfigProperties.SMTP_SECURITY); // Creo la mail HtmlEmail email = new HtmlEmail(); try { email.setHostName(smtp_host); email.setSmtpPort(smtp_port); email.setSSLOnConnect(smtp_security); email.setAuthentication(smtp_user, smtp_pwd); email.setFrom("gioco@gioco.com", "Gioco"); email.setSubject("Conferma il tuo indirizzo email " + confCode); email.addTo(address); email.setMsg("Messaggio della mail"); email.send(); logger.info("Email inviata"); } catch (EmailException ex) { logger.error("Errore nell'invio della mail"); logger.error(ex.getMessage()); } }
From source file:com.ning.metrics.meteo.publishers.AlertListener.java
private void createAndSendAlertEmail(String body) { try {//from w ww . j ava 2 s . c om log.info(String.format("Sending alert email to [%s]: %s", config.getRecipients(), body)); HtmlEmail email = new HtmlEmail(); email.setTextMsg(body); email.setFrom("esper-is-awesome@example.com"); email.setTo(Arrays.asList(new InternetAddress(config.getRecipients()))); email.setHostName(config.getHost()); email.setSmtpPort(config.getPort()); email.send(); } catch (Exception ex) { log.warn("Could not create or send email", ex); } }
From source file:libs.BuildMail.java
private void sendMail(String address, String subject, String msg) { try {/*from w w w . j ava 2 s. c om*/ HtmlEmail email = new HtmlEmail(); email.setHostName("smtp.ufpa.br"); email.setSmtpPort(25); email.setAuthenticator(new DefaultAuthenticator("david.lopes@icen.ufpa.br", "spiderteste")); //email.setSSLOnConnect(); TODO verficar a possiblidade de uso SMTP email.setFrom("david.lopes@icen.ufpa.br"); email.setSubject(subject); email.addTo(address); email.setHtmlMsg(msg); email.send(); } catch (EmailException error) { System.out.println("Email error: check your log file" + error.getMessage()); } }
From source file:com.smi.travel.util.Mail.java
public String sendmailwithAttchfile(String sendTo, String subject, String content, String attachfile, String sendCc) throws EmailException { String result = ""; boolean send = false; EmailAttachment attachment = new EmailAttachment(); HtmlEmail email = new HtmlEmail(); try {//w w w. ja va 2s. com if ((attachfile != null) && (!attachfile.equalsIgnoreCase(""))) { //attachment.setPath("C:\\Users\\Surachai\\Documents\\NetBeansProjects\\SMITravel\\test.txt"); attachment.setPath(attachfile); attachment.setDisposition(EmailAttachment.ATTACHMENT); attachment.setDescription("file attachment"); attachment.setName("text.txt"); email.attach(attachment); } send = true; } catch (EmailException ex) { System.out.println("Email Exception"); ex.printStackTrace(); result = "fail"; } if (send) { System.out.println(mail.getUsername() + mail.getPassword()); email.setHostName(mail.getHostname()); email.setSmtpPort(mail.getPort()); email.setAuthentication(mail.getUsername(), mail.getPassword()); email.setSSLOnConnect(true); email.setFrom(mail.getUsername()); email.setSubject(subject); email.setHtmlMsg(content); String[] toSplit = sendTo.split("\\,"); for (int i = 0; i < toSplit.length; i++) { System.out.println("Print toSplit" + toSplit[i]); email.addTo(toSplit[i]); } if (!sendCc.isEmpty()) { String[] ccSplit = sendCc.split("\\,"); for (int i = 0; i < ccSplit.length; i++) { System.out.println("Print ccSplit" + ccSplit[i]); email.addCc(ccSplit[i]); } } email.send(); result = "success"; } return result; }
From source file:edu.wright.cs.fa15.ceg3120.concon.server.EmailManager.java
/** * Add an outgoing email to the queue./*w ww.j av a 2 s . co m*/ * @param to Array of email addresses. * @param subject Header * @param body Content * @param attachmentFile Attachment */ public void addEmail(String[] to, String subject, String body, File attachmentFile) { HtmlEmail mail = new HtmlEmail(); Properties sysProps = System.getProperties(); // Setup mail server sysProps.setProperty("mail.smtp.host", props.getProperty("mail_server_hostname")); Session session = Session.getDefaultInstance(sysProps); try { mail.setMailSession(session); mail.setFrom(props.getProperty("server_email_addr"), props.getProperty("server_title")); mail.addTo(to); mail.setSubject(subject); mail.setTextMsg(body); mail.setHtmlMsg(composeAsHtml(mail, body)); if (attachmentFile.exists()) { EmailAttachment attachment = new EmailAttachment(); attachment.setPath(attachmentFile.getPath()); mail.attach(attachment); } } catch (EmailException e) { LOG.warn("Email was not added. ", e); } mailQueue.add(mail); }