List of usage examples for org.apache.commons.mail HtmlEmail setCharset
public void setCharset(final String newCharset)
From source file:br.com.rp.services.EmailService.java
private static HtmlEmail configurarEmailPadrao() throws EmailException { HtmlEmail email = new HtmlEmail(); email.setHostName("smtp.gmail.com"); email.setSmtpPort(465);//from www. j av a 2s . c o m email.setAuthentication(ENDERECO_EMAIL, SENHA); email.setSSLOnConnect(true); email.setCharset(StandardCharsets.UTF_8.toString()); email.setFrom(ENDERECO_EMAIL, "Sistema VBANK"); return email; }
From source file:com.baifendian.swordfish.common.mail.MailSendUtil.java
/** * ??//from ww w . ja va 2 s .co m * * @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:function.Email.java
public static void sendOrderEmail(String OrderID, String CustomnerEmail) { try {// w w w .jav a2s . co m HtmlEmail email = new HtmlEmail(); email.setHostName("smtp.googlemail.com"); email.setSmtpPort(465); email.setAuthenticator(new DefaultAuthenticator(MY_EMAIL, MY_PASSWORD)); email.setSSLOnConnect(true); email.setFrom(MY_EMAIL); email.addTo(CustomnerEmail); email.setSubject("Thanh ton thnh cng."); email.setHtmlMsg("<html><h2>Ha n ca bn vi m ha n <font color='red'>" + OrderID + "</font> thanh ton thnh cng.</h2>" + "<b>Cm n bn ng h chng ti!!!</b></div>" + "</html>"); email.setCharset("UTF-8"); email.setTextMsg("Trnh duyt khng h tr nh dng html!"); String a = email.send(); System.out.println(a); } catch (EmailException eex) { System.err.println(eex); } }
From source file:com.zxy.commons.email.MailMessageUtils.java
/** * HtmlEmail/*from ww w. j a v a 2s . c o m*/ * * @return HtmlEmail */ @SuppressWarnings("PMD.EmptyCatchBlock") private static HtmlEmail getEmail() { HtmlEmail email = new HtmlEmail(); email.setHostName(SMTP_HOST); email.setSmtpPort(SMTP_PORT); if (StringUtils.isNotBlank(SMTP_USERNAME) && StringUtils.isNotBlank(SMTP_PASSWORD)) { email.setAuthentication(SMTP_USERNAME, SMTP_PASSWORD); } try { Session session = email.getMailSession(); session.getProperties().setProperty("mail.smtp.ehlo", "true"); } catch (EmailException e) { // do nothing } if (StringUtils.isNotBlank(SMTP_MAIL_CHARSET)) { email.setCharset(SMTP_MAIL_CHARSET); } return email; }
From source file:function.Email.java
public static void sendVerifyEmail(Customers customer, String hash) { try {//from ww w . j av a 2 s .c o m HtmlEmail email = new HtmlEmail(); email.setHostName("smtp.googlemail.com"); email.setSmtpPort(465); email.setAuthenticator(new DefaultAuthenticator(MY_EMAIL, MY_PASSWORD)); email.setSSLOnConnect(true); email.setFrom(MY_EMAIL); email.addTo(customer.getEmail()); email.setSubject("Xc nhn ti khon TiviStore"); email.setHtmlMsg("<html><h2>Cho " + customer.getCustomerName() + ",</h2>" + "<div><b>Vui lng click vo <a href='http://localhost:8084/ThuongMaiDienTu/Verify?u=" + customer.getCustomerID() + "&hash=" + hash + "'>y</a> xc nhn ti khon...</b></div><br />" + "<b>Cm n bn ng h!!!</b></div>" + "</html>"); email.setCharset("UTF-8"); email.setTextMsg("Trnh duyt khng h tr nh dng html!"); String a = email.send(); System.out.println(a); } catch (EmailException eex) { System.err.println(eex); } }
From source file:mailbox.EmailHandler.java
private static void reply(IMAPMessage origin, String username, String emailAddress, String msg) { final HtmlEmail email = new HtmlEmail(); try {/*from www. java2 s.c om*/ email.setFrom(Config.getEmailFromSmtp(), Config.getSiteName()); email.addTo(emailAddress, username); String subject; if (!origin.getSubject().toLowerCase().startsWith("re:")) { subject = "Re: " + origin.getSubject(); } else { subject = origin.getSubject(); } email.setSubject(subject); email.setTextMsg(msg); email.setCharset("utf-8"); email.setSentDate(new Date()); email.addHeader("In-Reply-To", origin.getMessageID()); email.addHeader("References", origin.getMessageID()); Mailer.send(email); String escapedTitle = email.getSubject().replace("\"", "\\\""); String logEntry = String.format("\"%s\" %s", escapedTitle, email.getToAddresses()); play.Logger.of("mail").info(logEntry); } catch (Exception e) { Logger.warn("Failed to send an email: " + email + "\n" + ExceptionUtils.getStackTrace(e)); } }
From source file:com.github.robozonky.notifications.EmailHandler.java
private HtmlEmail createNewEmail(final SessionInfo session) throws EmailException { final HtmlEmail email = new HtmlEmail(); email.setCharset(Defaults.CHARSET.displayName()); // otherwise the e-mail contents are mangled email.setHostName(getSmtpHostname()); email.setSmtpPort(getSmtpPort());//from w w w . j a v a 2 s.c o m email.setStartTLSRequired(isStartTlsRequired()); email.setSSLOnConnect(isSslOnConnectRequired()); if (isAuthenticationRequired()) { final String username = getSmtpUsername(); LOGGER.debug("Will contact SMTP server as '{}'.", username); email.setAuthentication(getSmtpUsername(), getSmtpPassword()); } else { LOGGER.debug("Will contact SMTP server anonymously."); } email.setFrom(getSender(), session.getName()); email.addTo(getRecipient()); return email; }
From source file:com.vicky.common.utils.sendemail.SendEmailImpl.java
@Override public void send(Mail mail) throws Exception { try {/*from w w w . j a v a2 s.c o m*/ HtmlEmail htmlEmail = new HtmlEmail(); htmlEmail.setHostName(mail.getHost()); htmlEmail.setCharset(Mail.ENCODEING); htmlEmail.addTo(mail.getReceiverEmailAddress()); htmlEmail.setFrom(mail.getSenderEmailAddress(), mail.getName()); htmlEmail.setAuthentication(mail.getSenderUsername(), mail.getSenderPassword()); htmlEmail.setSubject(mail.getSubject()); htmlEmail.setMsg(mail.getMessage()); for (MailAttach mailFile : mail.getMailAttachs()) { EmailAttachment attachment = new EmailAttachment();// attachment.setPath(mailFile.getFilePath());//? //attachment.setURL(new URL("http://www.baidu.com/moumou"));//? attachment.setDisposition(EmailAttachment.ATTACHMENT); attachment.setName(MimeUtility.encodeText(mailFile.getFileName()));//?? htmlEmail.attach(attachment);//,? } htmlEmail.send(); } catch (Exception exception) { exception.printStackTrace(); this.logger.error("toString" + exception.toString()); this.logger.error("getMessage" + exception.getMessage()); this.logger.error("exception", exception); throw new StatusMsgException( "??,??,?,?V!"); } }
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"); }/*www . jav a 2 s.c om*/ 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; }
From source file:com.itcs.commons.email.impl.RunnableSendHTMLEmail.java
public void run() { Logger.getLogger(RunnableSendHTMLEmail.class.getName()).log(Level.INFO, "executing Asynchronous task RunnableSendHTMLEmail"); try {/* ww w .j av a2s. com*/ HtmlEmail email = new HtmlEmail(); email.setCharset("utf-8"); email.setMailSession(getSession()); for (String dir : to) { email.addTo(dir); } if (cc != null) { for (String ccEmail : cc) { email.addCc(ccEmail); } } if (cco != null) { for (String ccoEmail : cco) { email.addBcc(ccoEmail); } } email.setSubject(subject); // set the html message email.setHtmlMsg(body); email.setFrom(getSession().getProperties().getProperty(Email.MAIL_SMTP_FROM, Email.MAIL_SMTP_USER), getSession().getProperties().getProperty(Email.MAIL_SMTP_FROMNAME, Email.MAIL_SMTP_USER)); // set the alternative message email.setTextMsg("Si ve este mensaje, significa que su cliente de correo no permite mensajes HTML."); // send the email if (attachments != null) { addAttachments(email, attachments); } email.send(); Logger.getLogger(RunnableSendHTMLEmail.class.getName()).log(Level.INFO, "Email sent successfully to:{0} cc:{1} bcc:{2}", new Object[] { Arrays.toString(to), Arrays.toString(cc), Arrays.toString(cco) }); } catch (EmailException e) { Logger.getLogger(RunnableSendHTMLEmail.class.getName()).log(Level.SEVERE, "EmailException Error sending email... with properties:\n" + session.getProperties(), e); } }