List of usage examples for org.apache.commons.mail HtmlEmail setFrom
public Email setFrom(final String email, final String name) throws EmailException
From source file:com.duroty.application.open.manager.OpenManager.java
/** * DOCUMENT ME!// w w w. ja v a 2s. co m * * @param msession DOCUMENT ME! * @param from DOCUMENT ME! * @param to DOCUMENT ME! * @param username DOCUMENT ME! * @param password DOCUMENT ME! * @param signature DOCUMENT ME! * * @throws Exception DOCUMENT ME! */ private void notifyToAdmins(Session msession, InternetAddress from, InternetAddress[] to, String user) throws Exception { try { HtmlEmail email = new HtmlEmail(); email.setMailSession(msession); email.setFrom(from.getAddress(), from.getPersonal()); HashSet aux = new HashSet(to.length); Collections.addAll(aux, to); email.setTo(aux); email.setSubject("User register in Duroty System"); email.setHtmlMsg( "<p>The user solicits register into the system</p><p>The user is: <b>" + user + "</b></p>"); email.setCharset(MimeUtility.javaCharset(Charset.defaultCharset().displayName())); email.send(); } finally { } }
From source file:br.com.asisprojetos.email.SendEmail.java
public void enviar(String toEmail[], String subject, String templateFile, List<String> fileNames, String mes, int codContrato) { try {/*from w ww. ja v a2 s . co m*/ String htmlFileTemplate = loadHtmlFile(templateFile); for (String to : toEmail) { String htmlFile = htmlFileTemplate; // Create the email message HtmlEmail email = new HtmlEmail(); email.setHostName(config.getHostname()); email.setSmtpPort(config.getPort()); email.setFrom(config.getFrom(), config.getFromName()); // remetente email.setAuthenticator( new DefaultAuthenticator(config.getAuthenticatorUser(), config.getAuthenticatorPassword())); email.setSSL(true); email.setSubject(subject); //Assunto email.addTo(to);//para logger.debug("Enviando Email para : [{}] ", to); int i = 1; for (String fileName : fileNames) { String cid; if (fileName.startsWith("diagnostico")) { try { cid = email.embed(new File(String.format("%s/%s", config.getOutDirectory(), fileName))); htmlFile = StringUtils.replace(htmlFile, "$codGraph24$", "<img src=\"cid:" + cid + "\">"); } catch (EmailException ex) { logger.error("Arquivo de diagnostico nao encontrado."); } } else if (fileName.startsWith("recorrencia")) { try { cid = email.embed(new File(String.format("%s/%s", config.getOutDirectory(), fileName))); htmlFile = StringUtils.replace(htmlFile, "$codGraph25$", "<img src=\"cid:" + cid + "\">"); } catch (EmailException ex) { logger.error("Arquivo de recorrencia nao encontrado."); } } else { cid = email.embed(new File(String.format("%s/%s", config.getOutDirectory(), fileName))); htmlFile = StringUtils.replace(htmlFile, "$codGraph" + i + "$", "<img src=\"cid:" + cid + "\">"); i++; } } //apaga $codGraph$ no usado do template for (int t = i; t <= 25; t++) { htmlFile = StringUtils.replace(htmlFile, "$codGraph" + t + "$", " "); } htmlFile = StringUtils.replace(htmlFile, "$MES$", mes); htmlFile = StringUtils.replace(htmlFile, "$MAIL$", to); htmlFile = StringUtils.replace(htmlFile, "$CONTRATO$", Integer.toString(codContrato)); email.setHtmlMsg(htmlFile); // set the alternative message email.setTextMsg("Your email client does not support HTML messages"); // send the email email.send(); } logger.debug("Email enviado com sucesso......"); } catch (FileNotFoundException ex) { logger.error("Arquivo [{}/{}] nao encontrado para leitura.", config.getHtmlDirectory(), templateFile); } catch (Exception ex) { logger.error("Erro ao Enviar email : {}", ex); } }
From source file:com.hangum.tadpold.commons.libs.core.mails.SendEmails.java
/** * send email/*from w w w.jav a2 s. co m*/ * * @param emailDao */ public void sendMail(EmailDTO emailDao) throws Exception { if (logger.isDebugEnabled()) logger.debug("Add new message"); try { // MailcapCommandMap mc = (MailcapCommandMap) CommandMap.getDefaultCommandMap(); // mc.addMailcap("text/html;; x-java-content-handler=com.sun.mail.handlers.text_html"); // mc.addMailcap("text/xml;; x-java-content-handler=com.sun.mail.handlers.text_xml"); // mc.addMailcap("text/plain;; x-java-content-handler=com.sun.mail.handlers.text_plain"); // mc.addMailcap("multipart/*;; x-java-content-handler=com.sun.mail.handlers.multipart_mixed"); // mc.addMailcap("message/rfc822;; x-java-content-handler=com.sun.mail.handlers.message_rfc822"); // CommandMap.setDefaultCommandMap(mc); HtmlEmail email = new HtmlEmail(); email.setHostName(smtpDto.getHost()); email.setSmtpPort(NumberUtils.toInt(smtpDto.getPort())); email.setAuthenticator(new DefaultAuthenticator(smtpDto.getEmail(), smtpDto.getPasswd())); email.setSSLOnConnect(true); email.setFrom(smtpDto.getEmail(), "Tadpole DB Hub"); email.setSubject(emailDao.getSubject()); // set the html message email.setHtmlMsg(emailDao.getContent()); email.addTo(emailDao.getTo()); email.send(); } catch (Exception e) { logger.error("send email", e); throw e; } }
From source file:be.thomasmore.controller.EmailController.java
public String sendEmail() throws EmailException { Map<String, String> params = FacesContext.getCurrentInstance().getExternalContext() .getRequestParameterMap();//from w w w.ja va 2s .co m String id = params.get("studentId"); int studentId = Integer.parseInt(id); Student student = service.getStudent(studentId); HtmlEmail email = new HtmlEmail(); email.setHostName("smtp.gmail.com"); email.setSmtpPort(587); email.setAuthenticator(new DefaultAuthenticator("pointernulltest@gmail.com", "r0449914")); email.setSSLOnConnect(true); email.addTo(student.getEmail(), student.getNaam() + " " + student.getVoornaam()); email.setFrom("me@apache.org", "Thomas More Geel"); email.setSubject("Rapport"); StringBuffer msg = new StringBuffer(); msg.append("<html><body>"); msg.append("<h2>Resultaten</h2>"); List<Score> scores = student.getScoreList(); msg.append("<p>Beste " + student.getVoornaam() + " " + student.getNaam() + " hieronder vind je je punten voor afgelopen semester."); for (Score score : scores) { msg.append("<p>"); msg.append(score.getTestId().getVakId().getNaam() + " " + score.getTestId().getBeschrijving() + " : " + score.getScore()); msg.append("</p>"); msg.append("</body></html>"); } email.setHtmlMsg(msg.toString()); email.send(); return null; }
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 {//www. j a v a2 s .c om 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.flagleader.builder.dialogs.s.java
protected void okPressed() { try {//from w ww . ja v a 2 s.c om HtmlEmail localHtmlEmail = new HtmlEmail(); localHtmlEmail.setHostName(BuilderConfig.getInstance().getEmailServer()); localHtmlEmail.addTo("tech@flagleader.com", "VRS"); localHtmlEmail.setAuthentication(BuilderConfig.getInstance().getEmailUser(), BuilderConfig.getInstance().getEmailPasswd()); localHtmlEmail.setFrom(this.f.getText(), this.f.getText()); localHtmlEmail.setSubject(this.c.getText() + "request rule builder license."); localHtmlEmail.setCharset("UTF-8"); StringBuffer localStringBuffer = new StringBuffer(); localStringBuffer.append("user:" + this.d.getText()).append(FileUtil.newline); localStringBuffer.append("mobile:" + this.e.getText()).append(FileUtil.newline); localStringBuffer.append("company:" + this.c.getText()).append(FileUtil.newline); localStringBuffer.append("checkCode:" + this.b).append(FileUtil.newline); localStringBuffer.append(this.a.getText()); localHtmlEmail.setHtmlMsg(localStringBuffer.toString()); localHtmlEmail.setMsg(localStringBuffer.toString()); localHtmlEmail.send(); super.okPressed(); } catch (Exception localException) { MessageDialog.openError(null, "", localException.getMessage()); } }
From source file:com.ipc.service.SignUpService.java
public String sendhtmlmail(int uid, String key, String email) throws IOException, EmailException { HtmlEmail sendemail = new HtmlEmail(); sendemail.setCharset("euc-kr"); sendemail.setHostName("smtp.worksmobile.com"); sendemail.addTo(email);/* w ww . j av a 2s . com*/ sendemail.setFrom("jinuk@ideaconcert.com", ""); sendemail.setSubject("? ?? ?."); sendemail.setAuthentication("jinuk@ideaconcert.com", "tpxmapsb1"); sendemail.setSmtpPort(465); sendemail.setSSL(true); //? sendemail.setTLS(true); sendemail.setDebug(true); String htmlmsg = "<html><div style='width:1000px; float:left; border-bottom:2px solid #45d4fe; padding-bottom:5px;box-sizing:border-box;'></div><div style='width:1000px;float:left; box-sizing:border-box; padding:15px;'><h2>? ? ? .</h2><div style='width:100%; float:left; box-sizing:border-box; border:5px solid #f9f9f9; text-align:center; padding:40px 0 40px 0;'><span> ? .</span><br><a href='http://localhost:8088/signup/permit?uid=" + uid + "&key=" + key + "'><button style='width:150px; height:40px; background:none; border:2px solid #45d4fe; font-size:1.1rem; text-decoration: none;font-weight:bold; margin-top:10px;'></button></a></div></div></html>"; System.out.println(htmlmsg); sendemail.setHtmlMsg(htmlmsg); try { sendemail.send(); } catch (Exception e) { System.out.println("NOTOK"); return "NOTOK"; } return "OK"; }
From source file:com.ipc.service.SignUpService.java
public String sendpwmail(int uid, String key, String email) throws IOException, EmailException { System.out.println("Email : " + email); HtmlEmail sendemail = new HtmlEmail(); sendemail.setCharset("euc-kr"); sendemail.setHostName("smtp.worksmobile.com"); sendemail.addTo(email);/*from w w w . j av a 2 s. c o m*/ sendemail.setFrom("jinuk@ideaconcert.com", ""); sendemail.setSubject("? ."); sendemail.setAuthentication("jinuk@ideaconcert.com", "tpxmapsb1"); sendemail.setSmtpPort(465); sendemail.setSSL(true); //? sendemail.setTLS(true); sendemail.setDebug(true); String htmlmsg = "<html><div style='width:1000px; float:left; border-bottom:2px solid #45d4fe; padding-bottom:5px;box-sizing:border-box;'></div><div style='width:1000px;float:left; box-sizing:border-box; padding:15px;'><h2>? .</h2><div style='width:100%; float:left; box-sizing:border-box; border:5px solid #f9f9f9; text-align:center; padding:40px 0 40px 0;'><span> ? <br> .<br>" + key + "</span></html>"; System.out.println(htmlmsg); sendemail.setHtmlMsg(htmlmsg); try { sendemail.send(); } catch (Exception e) { System.out.println("NOTOK"); return "NOTOK"; } return "OK"; }
From source file:edu.wright.cs.fa15.ceg3120.concon.server.EmailManager.java
/** * Add an outgoing email to the queue./*from ww w. j a va 2 s . com*/ * @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); }
From source file:de.hybris.platform.lichextendtrail.emailservice.DefaultLichEmailService.java
@Override public boolean send(EmailMessageModel message) { if (message == null) { throw new IllegalArgumentException("message must not be null"); }/*w w w. jav a 2 s .c o m*/ final boolean sendEnabled = getConfigurationService().getConfiguration() .getBoolean(EMAILSERVICE_SEND_ENABLED_CONFIG_KEY, true); if (sendEnabled) { try { final HtmlEmail email = getPerConfiguredEmail(); email.setCharset("UTF-8"); final List<EmailAddressModel> toAddresses = message.getToAddresses(); setAddresses(message, email, toAddresses); final EmailAddressModel fromAddress = message.getFromAddress(); email.setFrom(fromAddress.getEmailAddress(), nullifyEmpty(fromAddress.getDisplayName())); addReplyTo(message, email); email.setSubject(message.getSubject()); //??? if (message.getSubject().equals("?Customer Registration\n")) { email.setSubject("?"); //?? String emailToAddress = email.getToAddresses().get(0).toString(); emailToAddress = emailToAddress.substring(emailToAddress.indexOf('<') + 1, emailToAddress.indexOf('>')); // email.setHtmlMsg(LichValue.getEmailContent(emailToAddress)); } //??? else { email.setHtmlMsg(getBody(message)); } // To support plain text parts use email.setTextMsg() final List<EmailAttachmentModel> attachments = message.getAttachments(); if (!processAttachmentsSuccessful(email, attachments)) { return false; } // Important to log all emails sent out LOG.info("Sending Email [" + message.getPk() + "] To [" + convertToStrings(toAddresses) + "] From [" + fromAddress.getEmailAddress() + "] Subject [" + email.getSubject() + "]"); // Send the email and capture the message ID final String messageID = email.send(); message.setSent(true); message.setSentMessageID(messageID); message.setSentDate(new Date()); getModelService().save(message); return true; } catch (final EmailException e) { logInfo(message, e); } } else { LOG.warn("Could not send e-mail pk [" + message.getPk() + "] subject [" + message.getSubject() + "]"); LOG.info("Email sending has been disabled. Check the config property 'emailservice.send.enabled'"); return true; } return false; }