List of usage examples for org.apache.commons.mail HtmlEmail setTextMsg
public HtmlEmail setTextMsg(final String aText) throws EmailException
From source file:com.ning.metrics.meteo.publishers.AlertListener.java
private void createAndSendAlertEmail(String body) { try {/*from w ww . j ava2s. com*/ 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:com.actionbazaar.email.EmailService.java
/** * Sends out an email/*w w w .j av a2s. co m*/ * @param message - message to be sent */ public void onMessage(Message message) { try { EmailRequest emailRequest = (EmailRequest) ((ObjectMessage) message).getObject(); Query query = entityManager.createQuery("select e from Email e where e.action = ?1"); query.setParameter(1, emailRequest.getAction()); List results = query.getResultList(); if (results.size() != 1) { logger.severe("A total of " + results.size() + " email templates were returned for action " + emailRequest.getAction()); return; } System.out.println("--> Sending email."); Email emailInfo = (Email) results.get(0); logger.info("Speaker Directory: " + attachmentDirectory); HtmlEmail email = new HtmlEmail(); email.setMailSession(mailSession); email.setTextMsg("Hello World!"); // email.setSubject(template.getSubject()); email.addTo("rcuprak@mac.com"); email.setFrom("java@ctjava.org"); // email.send(); /* emailTemplate.process(emailRecipient.getReplacementTokens()); for (Map.Entry<String,File> entry : emailTemplate.getCidMappings().entrySet()) { email.embed(entry.getValue(),entry.getKey()); } email.setHtmlMsg(emailTemplate.getPatchedEmail()); */ } catch (Throwable t) { t.printStackTrace(); //context.setRollbackOnly(); } }
From source file:com.github.robozonky.notifications.EmailHandler.java
@Override public void send(final SessionInfo sessionInfo, final String subject, final String message, final String fallbackMessage) throws Exception { final HtmlEmail email = createNewEmail(sessionInfo); email.setSubject(subject);// ww w . j a v a 2 s .c o m email.setHtmlMsg(message); email.setTextMsg(fallbackMessage); LOGGER.debug("Will send '{}' from {} to {} through {}:{} as {}.", email.getSubject(), email.getFromAddress(), email.getToAddresses(), email.getHostName(), email.getSmtpPort(), getSmtpUsername()); email.send(); }
From source file:com.qatickets.service.MailService.java
public void send(EmailMessage msg) throws Exception { HtmlEmail email = new HtmlEmail(); email.setSmtpPort(port);/*from w ww . ja v a2 s . c om*/ email.setHostName(host); email.setHtmlMsg(msg.getHTMLContent()); email.setTextMsg(msg.getTextContent()); email.setSubject(msg.getSubject()); email.addTo(msg.getRecepient().getEmail(), msg.getRecepient().getName()); // email.setFrom(systemOwner, "QATickets.com"); email.send(); }
From source file:com.jaeksoft.searchlib.config.Mailer.java
public void send() throws EmailException { if (email instanceof HtmlEmail) { HtmlEmail htmlEmail = (HtmlEmail) email; if (htmlStringWriter != null) htmlEmail.setHtmlMsg(htmlStringWriter.toString()); if (textStringWriter != null) htmlEmail.setTextMsg(textStringWriter.toString()); else/* w w w . j a va 2 s . c o m*/ htmlEmail.setTextMsg("This message contains an HTML content"); } else if (email instanceof SimpleEmail) { SimpleEmail simpleEmail = (SimpleEmail) email; if (textStringWriter != null) simpleEmail.setMsg(textStringWriter.toString()); } if (textStringWriter != null) email.send(); }
From source file:com.irurueta.server.commons.email.ApacheMailHtmlEmailMessage.java
/** * Builds email content to be sent using an email sender. * @param content instance where content must be set. * @throws com.irurueta.server.commons.email.EmailException if setting mail * content fails./*from ww w . jav a 2 s. c o m*/ */ @Override protected void buildContent(HtmlEmail content) throws com.irurueta.server.commons.email.EmailException { try { if (getAlternativeText() != null) { content.setTextMsg(getAlternativeText()); } //process inline attachments boolean[] generated = processInlineAttachments(); if (getHtmlContent() != null) { content.setHtmlMsg(process(getHtmlContent(), generated)); } //all attachments go into general message multipar //add inline attachments List<InlineAttachment> inlineAttachments = getInlineAttachments(); if (inlineAttachments != null) { for (InlineAttachment attachment : inlineAttachments) { //only add attachments with files and content ids if (attachment.getContentId() == null || attachment.getAttachment() == null) { continue; } content.embed(attachment.getAttachment(), attachment.getContentId()); } } //add other attachments parts List<EmailAttachment> attachments = getEmailAttachments(); org.apache.commons.mail.EmailAttachment apacheAttachment; if (attachments != null) { for (EmailAttachment attachment : attachments) { //only add attachments with files if (attachment.getAttachment() == null) { continue; } apacheAttachment = new org.apache.commons.mail.EmailAttachment(); apacheAttachment.setPath(attachment.getAttachment().getAbsolutePath()); apacheAttachment.setDisposition(org.apache.commons.mail.EmailAttachment.ATTACHMENT); if (attachment.getName() != null) { apacheAttachment.setName(attachment.getName()); } content.attach(apacheAttachment); } } } catch (EmailException e) { throw new com.irurueta.server.commons.email.EmailException(e); } }
From source file:com.ms.commons.message.impl.sender.AbstractEmailSender.java
private MultiPartEmail makeHtmlEmail(MsunMail mail, String charset) throws EmailException { HtmlEmail email = new HtmlEmail(); email.setCharset(charset);/*from w ww . j a v a 2 s . com*/ if (!StringUtils.isEmpty(mail.getMessage())) { email.setTextMsg(mail.getMessage()); } email.setHtmlMsg(mail.getHtmlMessage()); return email; }
From source file:cl.alma.scrw.bpmn.tasks.MailActivityBehavior.java
protected HtmlEmail createHtmlEmail(String text, String html) { HtmlEmail email = new HtmlEmail(); try {// w ww.ja v a 2s. c om email.setHtmlMsg(html); if (text != null) { // for email clients that don't support html email.setTextMsg(text); } return email; } catch (EmailException e) { throw new ActivitiException("Could not create HTML email", e); } }
From source file:com.manydesigns.mail.sender.DefaultMailSender.java
protected void send(Email emailBean) throws EmailException { logger.debug("Entering send(Email)"); org.apache.commons.mail.Email email; String textBody = emailBean.getTextBody(); String htmlBody = emailBean.getHtmlBody(); if (null == htmlBody) { if (emailBean.getAttachments().isEmpty()) { SimpleEmail simpleEmail = new SimpleEmail(); simpleEmail.setMsg(textBody); email = simpleEmail;// www .ja v a 2s.co m } else { MultiPartEmail multiPartEmail = new MultiPartEmail(); multiPartEmail.setMsg(textBody); for (Attachment attachment : emailBean.getAttachments()) { EmailAttachment emailAttachment = new EmailAttachment(); emailAttachment.setName(attachment.getName()); emailAttachment.setDisposition(attachment.getDisposition()); emailAttachment.setDescription(attachment.getDescription()); emailAttachment.setPath(attachment.getFilePath()); multiPartEmail.attach(emailAttachment); } email = multiPartEmail; } } else { HtmlEmail htmlEmail = new HtmlEmail(); htmlEmail.setHtmlMsg(htmlBody); if (textBody != null) { htmlEmail.setTextMsg(textBody); } for (Attachment attachment : emailBean.getAttachments()) { if (!attachment.isEmbedded()) { EmailAttachment emailAttachment = new EmailAttachment(); emailAttachment.setName(attachment.getName()); emailAttachment.setDisposition(attachment.getDisposition()); emailAttachment.setDescription(attachment.getDescription()); emailAttachment.setPath(attachment.getFilePath()); htmlEmail.attach(emailAttachment); } else { FileDataSource dataSource = new FileDataSource(new File(attachment.getFilePath())); htmlEmail.embed(dataSource, attachment.getName(), attachment.getContentId()); } } email = htmlEmail; } if (null != login && null != password) { email.setAuthenticator(new DefaultAuthenticator(login, password)); } email.setHostName(server); email.setSmtpPort(port); email.setSubject(emailBean.getSubject()); email.setFrom(emailBean.getFrom()); // hongliangpan add if ("smtp.163.com".equals(server)) { email.setFrom(login + "@163.com"); // email.setAuthenticator(new DefaultAuthenticator("test28797575", "1qa2ws3ed")); } for (Recipient recipient : emailBean.getRecipients()) { switch (recipient.getType()) { case TO: email.addTo(recipient.getAddress()); break; case CC: email.addCc(recipient.getAddress()); break; case BCC: email.addBcc(recipient.getAddress()); break; } } email.setSSL(ssl); email.setTLS(tls); email.setSslSmtpPort(port + ""); email.setCharset("UTF-8"); email.send(); logger.debug("Exiting send(Email)"); }
From source file:com.fatecib.projetoemail.servlets.DAO.Enviaremail2.java
private void enviar(Email em, ConfiguracaoSQL conf, String destinatario) throws EmailException { try {/*from w w w . j a va 2s. c o m*/ HtmlEmail email = new HtmlEmail(); email.setHostName(conf.getEMAILHOST()); email.setSmtpPort(conf.getPORTASMTP()); email.setAuthenticator(new DefaultAuthenticator(conf.getUsuario(), conf.getSENHA())); email.setSSL(true); email.setFrom(conf.getUsuario()); email.setSubject(em.getTitulo()); email.setHtmlMsg(em.getConteudo()); // set the alternative message email.setTextMsg("Email enviado com sucesso"); email.addTo(destinatario); email.send(); } catch (Exception e) { throw e; } }