List of usage examples for org.apache.commons.mail HtmlEmail setTLS
@Deprecated public void setTLS(final boolean withTLS)
From source file:com.sigaf.bean.MailReset.java
public static HtmlEmail conectaEmail() throws EmailException { HtmlEmail email = new HtmlEmail(); email.setHostName(HOSTNAME);/*w w w .j av a2s .c om*/ email.setSmtpPort(587); email.setSSL(true); email.setAuthenticator(new DefaultAuthenticator(USERNAME, PASSWORD)); email.setTLS(true); email.setFrom(EMAILORIGEM); return email; }
From source file:br.com.itfox.utils.SendHtmlFormatedEmail.java
public void sendingHtml(String orderDetails, String orderNumber, String toName, String toEmail) { try {/*from w w w . ja va2 s . c om*/ // Create the email message HtmlEmail email = new HtmlEmail(); email.setHostName("smtp.gmail.com"); email.setSmtpPort(587); email.setAuthenticator(new DefaultAuthenticator("belchiorpalma@gmail.com", "xp2002b5")); email.setSSLOnConnect(true); email.setTLS(true); email.setFrom("contato@itfox.com.br"); //email.setSubject("TestMail"); email.addTo(toEmail, toName); //email.setFrom("belchiorpalma@me.com", "Me"); //email.setSubject("Test email with inline image"); email.setSubject(MimeUtility.encodeText("Thank you for your order", "UTF-8", "B")); // embed the image and get the content id //URL url = new URL("http://boutiquecellars.com/img/white-wines.jpg"); //String cid = email.embed(url, "BoutiqueCellars.com"); // set the html message email.setHtmlMsg("Thank you for your order\n<br/><br/>" + "\n" + "We received your order #" + orderNumber + " and we are working on it now.\n<br/>" + "We will e-mail you an update as soon as your order is processed.\n<br/>" + "\n<br/>" + "Boutique Cellars team\n" + "\n<br/><br/><img src='http://boutiquecellars.com/img/logoemail.jpg'/> \n" + //orderDetails + "<br/><br/>BOUTIQUE CELLARS SUPPORTS THE RESPONSIBLE SERVICE OF ALCOHOL. NSW: UNDER THE LIQUOR\n<br/>" + "ACT 2007 IT IS AGAINST THE LAW TO SELL OR SUPPLY ALCOHOL TO, OR TO OBTAIN ALCOHOL ON\n<br/>" + "BEHALF OF, A PERSON UNDER THE AGE OF 18 YEARS. NSW PACKAGED LIQUOR LICENCE NUMBER\n<br/>" + "LIQP770016947. YOUR CONTRACT OF SALE IS WITH THE RELEVANT LICENSEE AT THE RELEVANT\n<br/>" + "PREMISES FROM WHICH YOU ORDER IS ACCEPTED AND FULFILLED. LIQUOR IS SOLD FROM OUR\n<br/>" + "PLATFORM ON BEHALF OF THE RELEVANT LICENSEE. ACCORDINGLY, YOUR OFFER TO PURCHASE IS\n<br/>" + "SUBJECT TO ACCEPTANCE OF YOUR OFFER BY THE HOLDER OF THE LIQUOR LICENCE, CERTIFICATION\n<br/>" + "AND EVIDENCE OF YOU BEING OVER 18 YEARS OF AGE, THE AVAILABILITY OF STOCK AND THE\n<br/>" + "LIQUOR WHICH IS THE SUBJECT MATTER OF YOUR OFFER BEING ASCERTAINED AND APPROPRIATED\n<br/>" + "AT THE ABOVE MENTIONED LICENSED PREMISES.<br/><br/>" + " Boutique Cellar Imports Pty Ltd | ABN 69 607 265 618"); // set the alternative message email.setTextMsg( "Thank you for your order, We received your order #18765 and we are working on it now.\n" + "We will e-mail you an update as soon as your order is processed.\n" + "\n" + "Boutique Cellars team"); // send the email email.send(); } catch (EmailException ex) { Logger.getLogger(SendHtmlFormatedEmail.class.getName()).log(Level.SEVERE, null, ex); } catch (UnsupportedEncodingException ex) { Logger.getLogger(SendHtmlFormatedEmail.class.getName()).log(Level.SEVERE, null, ex); } /*} catch (MalformedURLException ex) { Logger.getLogger(SendHtmlFormatedEmail.class.getName()).log(Level.SEVERE, null, ex); }*/ }
From source file:de.maklerpoint.office.Schnittstellen.Email.MultiEmailSender.java
public void send() throws EmailException { if (files != null && urls != null) { attachments = new EmailAttachment[files.length + urls.length]; int cnt = 0; for (int i = 0; i < files.length; i++) { attachments[cnt] = new EmailAttachment(); attachments[cnt].setPath(files[i].getPath()); attachments[cnt].setName(files[i].getName()); attachments[cnt].setDisposition(EmailAttachment.ATTACHMENT); cnt++;//from w w w .j a va 2 s. c o m } for (int i = 0; i < urls.length; i++) { attachments[cnt] = new EmailAttachment(); attachments[cnt].setURL(urls[i]); attachments[cnt].setName(urls[i].getFile()); attachments[cnt].setDisposition(EmailAttachment.ATTACHMENT); cnt++; } } else if (files != null) { attachments = new EmailAttachment[files.length]; for (int i = 0; i < files.length; i++) { attachments[i] = new EmailAttachment(); attachments[i].setPath(files[i].getPath()); attachments[i].setName(files[i].getName()); attachments[i].setDisposition(EmailAttachment.ATTACHMENT); } } else if (urls != null) { attachments = new EmailAttachment[urls.length]; for (int i = 0; i < urls.length; i++) { attachments[i] = new EmailAttachment(); attachments[i].setURL(urls[i]); attachments[i].setName(urls[i].getFile()); attachments[i].setDisposition(EmailAttachment.ATTACHMENT); } } HtmlEmail email = new HtmlEmail(); email.setHostName(Config.get("mailHost", "")); email.setSmtpPort(Config.getConfigInt("mailPort", 25)); email.setTLS(Config.getConfigBoolean("mailTLS", false)); email.setSSL(Config.getConfigBoolean("mailSSL", false)); //email.setSslSmtpPort(Config.getConfigInt("emailPort", 25)); email.setAuthenticator( new DefaultAuthenticator(Config.get("mailUsername", ""), Config.get("mailPassword", ""))); email.setFrom(Config.get("mailSendermail", "info@example.de"), Config.get("mailSender", null)); email.setSubject(subject); email.setHtmlMsg(body); email.setTextMsg(nohtmlmsg); for (int i = 0; i < adress.length; i++) { email.addTo(adress[i]); } if (cc != null) { for (int i = 0; i < cc.length; i++) { email.addCc(cc[i]); } } if (attachments != null) { for (int i = 0; i < attachments.length; i++) { email.attach(attachments[i]); } } email.send(); }
From source file:it.vige.greenarea.test.mail.SendMailTest.java
@Test public void testSendMailToGoogle() throws Exception { HtmlEmail email = new HtmlEmail(); try {//from www. jav a 2 s.com email.setSubject("prova"); email.setHtmlMsg("<div>ciao</div>"); email.addTo("luca.stancapiano@vige.it"); email.setSmtpPort(587); email.setHostName("smtp.gmail.com"); email.setFrom("greenareavige@gmail.com"); email.setAuthentication("greenareavige@gmail.com", "vulitgreenarea"); email.setTLS(true); email.send(); } catch (EmailException e) { fail(); } }
From source file:com.elexcode.emailservicelibrary.service.EmailSenderServiceImpl.java
@Override public void sendEmail(EmailObject emailObject) throws Exception { HtmlEmail email = new HtmlEmail(); email.setHostName(host);/* w ww.j av a2 s.co m*/ email.setSmtpPort(port); email.setAuthentication(username, password); for (String recipient : emailObject.getRecipients()) { email.addTo(recipient); } email.setFrom(username); email.setSubject(emailObject.getSubject()); if (checkStringNotNullNotEmpty(emailObject.getHtmlMsg())) { email.setHtmlMsg(emailObject.getHtmlMsg()); } else { if (checkStringNotNullNotEmpty(emailObject.getMessage())) { email.setTextMsg(emailObject.getMessage()); } } email.setDebug(false); email.setTLS(true); email.setSSL(true); email.send(); }
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);/*from w w w. j ava 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> ? .</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 ww .j av a 2s. co 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:br.com.atmatech.sac.controller.Email.java
public void emai(String smtp, String user, String password, Integer porta, Boolean ssl, Boolean tls, String emailto, String emailfrom, String conteudo, String assunto) throws EmailException, MalformedURLException { HtmlEmail email = new HtmlEmail(); email.setHostName(smtp); // o servidor SMTP para envio do e-mail email.addTo(emailto);//destinatario conteudo = conteudo.replaceAll("\n", "<p>"); email.setFrom(emailfrom); // remetente //email.addCc(emailfrom); email.setSubject(assunto);/*from w w w.j av a 2s .c om*/ // configura a mensagem para o formato HTML email.setHtmlMsg("<html><meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">" + conteudo + "</html>"); email.setAuthentication(user, password); email.setSmtpPort(porta); email.setSSL(ssl); email.setTLS(tls); email.send(); }
From source file:com.baasbox.service.user.UserService.java
public static void sendResetPwdMail(String appCode, ODocument user) throws Exception { final String errorString = "Cannot send mail to reset the password: "; //check method input if (!user.getSchemaClass().getName().equalsIgnoreCase(UserDao.MODEL_NAME)) throw new PasswordRecoveryException(errorString + " invalid user object"); //initialization String siteUrl = Application.NETWORK_HTTP_URL.getValueAsString(); int sitePort = Application.NETWORK_HTTP_PORT.getValueAsInteger(); if (StringUtils.isEmpty(siteUrl)) throw new PasswordRecoveryException(errorString + " invalid site url (is empty)"); String textEmail = PasswordRecovery.EMAIL_TEMPLATE_TEXT.getValueAsString(); String htmlEmail = PasswordRecovery.EMAIL_TEMPLATE_HTML.getValueAsString(); if (StringUtils.isEmpty(htmlEmail)) htmlEmail = textEmail;//from ww w.j a v a2 s . c om if (StringUtils.isEmpty(htmlEmail)) throw new PasswordRecoveryException(errorString + " text to send is not configured"); boolean useSSL = PasswordRecovery.NETWORK_SMTP_SSL.getValueAsBoolean(); boolean useTLS = PasswordRecovery.NETWORK_SMTP_TLS.getValueAsBoolean(); String smtpHost = PasswordRecovery.NETWORK_SMTP_HOST.getValueAsString(); int smtpPort = PasswordRecovery.NETWORK_SMTP_PORT.getValueAsInteger(); if (StringUtils.isEmpty(smtpHost)) throw new PasswordRecoveryException(errorString + " SMTP host is not configured"); String username_smtp = null; String password_smtp = null; if (PasswordRecovery.NETWORK_SMTP_AUTHENTICATION.getValueAsBoolean()) { username_smtp = PasswordRecovery.NETWORK_SMTP_USER.getValueAsString(); password_smtp = PasswordRecovery.NETWORK_SMTP_PASSWORD.getValueAsString(); if (StringUtils.isEmpty(username_smtp)) throw new PasswordRecoveryException(errorString + " SMTP username is not configured"); } String emailFrom = PasswordRecovery.EMAIL_FROM.getValueAsString(); String emailSubject = PasswordRecovery.EMAIL_SUBJECT.getValueAsString(); if (StringUtils.isEmpty(emailFrom)) throw new PasswordRecoveryException(errorString + " sender email is not configured"); try { String userEmail = ((ODocument) user.field(UserDao.ATTRIBUTES_VISIBLE_ONLY_BY_THE_USER)).field("email") .toString(); String username = (String) ((ODocument) user.field("user")).field("name"); //Random String sRandom = appCode + "%%%%" + username + "%%%%" + UUID.randomUUID(); String sBase64Random = new String(Base64.encodeBase64(sRandom.getBytes())); //Save on DB ResetPwdDao.getInstance().create(new Date(), sBase64Random, user); //Send mail HtmlEmail email = null; URL resetUrl = new URL(Application.NETWORK_HTTP_SSL.getValueAsBoolean() ? "https" : "http", siteUrl, sitePort, "/user/password/reset/" + sBase64Random); //HTML Email Text ST htmlMailTemplate = new ST(htmlEmail, '$', '$'); htmlMailTemplate.add("link", resetUrl); htmlMailTemplate.add("user_name", username); htmlMailTemplate.add("token", sBase64Random); //Plain text Email Text ST textMailTemplate = new ST(textEmail, '$', '$'); textMailTemplate.add("link", resetUrl); textMailTemplate.add("user_name", username); textMailTemplate.add("token", sBase64Random); email = new HtmlEmail(); email.setHtmlMsg(htmlMailTemplate.render()); email.setTextMsg(textMailTemplate.render()); //Email Configuration email.setSSL(useSSL); email.setSSLOnConnect(useSSL); email.setTLS(useTLS); email.setStartTLSEnabled(useTLS); email.setStartTLSRequired(useTLS); email.setSSLCheckServerIdentity(false); email.setSslSmtpPort(String.valueOf(smtpPort)); email.setHostName(smtpHost); email.setSmtpPort(smtpPort); email.setCharset("utf-8"); if (PasswordRecovery.NETWORK_SMTP_AUTHENTICATION.getValueAsBoolean()) { email.setAuthenticator(new DefaultAuthenticator(username_smtp, password_smtp)); } email.setFrom(emailFrom); email.addTo(userEmail); email.setSubject(emailSubject); if (BaasBoxLogger.isDebugEnabled()) { StringBuilder logEmail = new StringBuilder().append("HostName: ").append(email.getHostName()) .append("\n").append("SmtpPort: ").append(email.getSmtpPort()).append("\n") .append("SslSmtpPort: ").append(email.getSslSmtpPort()).append("\n") .append("SSL: ").append(email.isSSL()).append("\n").append("TLS: ").append(email.isTLS()) .append("\n").append("SSLCheckServerIdentity: ").append(email.isSSLCheckServerIdentity()) .append("\n").append("SSLOnConnect: ").append(email.isSSLOnConnect()).append("\n") .append("StartTLSEnabled: ").append(email.isStartTLSEnabled()).append("\n") .append("StartTLSRequired: ").append(email.isStartTLSRequired()).append("\n") .append("SubType: ").append(email.getSubType()).append("\n") .append("SocketConnectionTimeout: ").append(email.getSocketConnectionTimeout()).append("\n") .append("SocketTimeout: ").append(email.getSocketTimeout()).append("\n") .append("FromAddress: ").append(email.getFromAddress()).append("\n").append("ReplyTo: ") .append(email.getReplyToAddresses()).append("\n").append("BCC: ") .append(email.getBccAddresses()).append("\n").append("CC: ").append(email.getCcAddresses()) .append("\n") .append("Subject: ").append(email.getSubject()).append("\n") //the following line throws a NPE in debug mode //.append("Message: ").append(email.getMimeMessage().getContent()).append("\n") .append("SentDate: ").append(email.getSentDate()).append("\n"); BaasBoxLogger.debug("Password Recovery is ready to send: \n" + logEmail.toString()); } email.send(); } catch (EmailException authEx) { BaasBoxLogger.error("ERROR SENDING MAIL:" + ExceptionUtils.getStackTrace(authEx)); throw new PasswordRecoveryException( errorString + " Could not reach the mail server. Please contact the server administrator"); } catch (Exception e) { BaasBoxLogger.error("ERROR SENDING MAIL:" + ExceptionUtils.getStackTrace(e)); throw new Exception(errorString, e); } }
From source file:br.com.atmatech.sac.controller.Email.java
public void emaiMassa(String smtp, String user, String password, Integer porta, Boolean ssl, Boolean tls, List<PessoaBeans> emailto, String emailfrom, String conteudo, String assunto) throws EmailException, MalformedURLException { HtmlEmail email = new HtmlEmail(); email.setHostName(smtp); // o servidor SMTP para envio do e-mail Integer indice2 = 0;/* w ww . j a v a 2 s . c o m*/ Integer j = 0; for (int i = 0; (i < emailto.size()) && (i < 45); i++) { email.addTo(emailto.get(i).getEmail());//destinatario indice2 = i; } while (j <= indice2) { emailto.remove(0); j++; } conteudo = conteudo.replaceAll("\n", "<p>"); email.setFrom(emailfrom); // remetente //email.addCc(emailfrom); email.setSubject(assunto); // configura a mensagem para o formato HTML email.setHtmlMsg("<html><meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">" + conteudo + "</html>"); email.setAuthentication(user, password); email.setSmtpPort(porta); email.setSSL(ssl); email.setTLS(tls); email.send(); if (emailto != null) { if (emailto.size() > 1) { emaiMassa(smtp, user, password, porta, ssl, tls, emailto, emailfrom, conteudo, assunto); } } }