List of usage examples for javax.mail Message setSubject
public abstract void setSubject(String subject) throws MessagingException;
From source file:fr.xebia.cocktail.MailService.java
public void sendCocktail(Cocktail cocktail, String recipient, String cocktailPageUrl) throws MessagingException { Message msg = new MimeMessage(mailSession); msg.setFrom(fromAddress);/*w w w. ja va2 s . co m*/ msg.addRecipient(Message.RecipientType.TO, new InternetAddress(recipient)); msg.setSubject("[Cocktail] " + cocktail.getName()); String message = cocktail.getName() + "\n" // + "--------------------\n" // + "\n" // + Strings.nullToEmpty(cocktail.getInstructions()) + "\n" // + "\n" // + cocktailPageUrl; msg.setContent(message, "text/plain"); Transport.send(msg); auditLogger.info("Sent to {} cocktail '{}'", recipient, cocktail.getName()); sentEmailCounter.incrementAndGet(); }
From source file:com.cloudbees.demo.beesshop.service.MailService.java
public void sendProductEmail(Product product, String recipient, String cocktailPageUrl) throws MessagingException { Message msg = new MimeMessage(mailSession); msg.setFrom(fromAddress);// ww w . j a v a 2s. co m msg.addRecipient(Message.RecipientType.TO, new InternetAddress(recipient)); msg.setSubject("[BeesShop] Check this product: " + product.getName()); String message = product.getName() + "\n" // + "--------------------\n" // + "\n" // + Strings.nullToEmpty(product.getDescription()) + "\n" // + "\n" // + cocktailPageUrl; msg.setContent(message, "text/plain"); mailSession.getTransport().send(msg); auditLogger.info("Sent to {} product '{}'", recipient, product.getName()); sentEmailCounter.incrementAndGet(); }
From source file:com.cloudbees.demo.beesshop.service.MailService.java
public void sendOrderConfirmation(ShoppingCart shoppingCart, String recipient) { try {/*from w w w.ja va 2 s . com*/ Message msg = new MimeMessage(mailSession); msg.setFrom(fromAddress); msg.addRecipient(Message.RecipientType.TO, new InternetAddress(recipient)); msg.setSubject("[BeesShop] Order Confirmation: " + shoppingCart.getItems() + " items - " + shoppingCart.getPrettyPrice()); String message = "ORDER CONFIRMATION\n" + "\n" + "* Purchased items: " + shoppingCart.getItemsCount() + "\n" + "* Price: " + shoppingCart.getPrettyPrice() + "\n"; for (ShoppingCart.ShoppingCartItem item : shoppingCart.getItems()) { message += " * " + item.getQuantity() + "x" + item.getProduct().getName() + "\n"; } msg.setContent(message, "text/plain"); Transport.send(msg); auditLogger.info("Sent to {} shopping cart with value of '{}'", recipient, shoppingCart.getPrettyPrice()); sentEmailCounter.incrementAndGet(); } catch (MessagingException e) { logger.warn("Exception sending order confirmation email to {}", recipient, e); } }
From source file:com.esri.gpt.framework.mail.MailRequest.java
/** * Sends the E-Mail message./* w w w . j av a 2 s . com*/ * @throws AddressException if an E-Mail address is invalid * @throws MessagingException if an exception occurs */ public void send() throws AddressException, MessagingException { // setup the mail server properties Properties props = new Properties(); props.put("mail.smtp.host", getHost()); if (getPort() > 0) { props.put("mail.smtp.port", "" + getPort()); } // set up the message Session session = Session.getDefaultInstance(props, _authenticator); Message message = new MimeMessage(session); message.setSubject(getSubject()); message.setContent(getBody(), getMimeType()); message.setFrom(makeAddress(escapeHtml4(stripControls(getFromAddress())))); for (String sTo : getRecipients()) { message.addRecipient(Message.RecipientType.TO, makeAddress(sTo)); } // send the message Transport.send(message); }
From source file:yoyo.framework.enterprise.infra.messaging.MailServiceImpl.java
/** * ??/*from w w w . j a v a2 s .c o m*/ * @param from FROM * @param to TO * @param subject ?? * @return * @throws EnterpriseException ?? */ private Message createMessage(final String from, final String to, final String subject) throws EnterpriseException { Validate.notNull(session, "????????"); try { final Message message = new MimeMessage(session); message.setFrom(new InternetAddress(from)); message.addRecipient(Message.RecipientType.TO, new InternetAddress(to)); message.setSubject(subject); return message; } catch (final AddressException e) { throw new EnterpriseException(e.getLocalizedMessage()); } catch (final MessagingException e) { throw new EnterpriseException(e.getLocalizedMessage()); } }
From source file:org.nekorp.workflow.desktop.servicio.imp.ServicioAlertaVerificacionEmailImp.java
@Override public void enviarAlerta(List<AlertaVerificacion> alertas) { try {//from w w w . j a va 2 s. c o m for (AlertaVerificacion x : alertas) { Message message = new MimeMessage(template.buildSession()); message.setFrom(new InternetAddress(template.getMailSender())); message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(template.getMailRecipient())); message.setSubject("Alerta de Verificacin"); ST contenido = new ST(contenidoRaw); contenido.add("placas", x.getPlacas()); contenido.add("periodo", x.getPeriodo()); message.setText(contenido.render()); Transport.send(message); } } catch (MessagingException e) { throw new RuntimeException(e); } }
From source file:ips1ap101.ejb.core.mail.MailerBean.java
@Override public Message sendMessage(String addressList, String subject, String text) throws MessagingException { if (EA.isMailingEnabled()) { } else {/*from ww w .j av a 2s. co m*/ return null; } if (StringUtils.isBlank(addressList)) { throw new InvalidParameterException("addressList"); } if (StringUtils.isBlank(subject)) { throw new InvalidParameterException("subject"); } if (StringUtils.isBlank(text)) { throw new InvalidParameterException("text"); } Address[] internetAddressList = InternetAddress.parse(addressList, false); Date timeStamp = new Date(); Message message = new MimeMessage(session); message.setFrom(); message.setHeader("X-Mailer", "JavaMail"); message.setRecipients(Message.RecipientType.TO, internetAddressList); message.setSentDate(timeStamp); message.setSubject(subject); message.setText(text); Transport.send(message); return message; }
From source file:org.nekorp.workflow.desktop.servicio.imp.ServicioAlertaEmailImp.java
@Override public void enviarAlerta(List<AlertaServicio> alertas) { try {/* ww w . j ava 2 s .c o m*/ for (AlertaServicio x : alertas) { Message message = new MimeMessage(template.buildSession()); message.setFrom(new InternetAddress(template.getMailSender())); message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(template.getMailRecipient())); message.setSubject("Alerta"); ST contenido = new ST(contenidoRaw); contenido.add("cliente", x.getNombreCliente()); contenido.add("tipo", x.getTipoAuto()); contenido.add("marca", x.getMarcaAuto()); contenido.add("placas", x.getPlacasAuto()); contenido.add("kilometraje", x.getKilometrajeAuto()); contenido.add("servicio", x.getDescripcionServicio()); contenido.add("kilometrajeServicio", x.getKilometrajeServicio()); message.setText(contenido.render()); Transport.send(message); } } catch (MessagingException e) { throw new RuntimeException(e); } }
From source file:mb.MbTermin.java
private void posaljiMail(Student student, Profesor profesorId, Termin t) { //ToDo change username and password for google account final String username = "*****"; final String password = "*****"; Properties props = new Properties(); props.put("mail.smtp.auth", "true"); props.put("mail.smtp.starttls.enable", "true"); props.put("mail.smtp.host", "smtp.gmail.com"); props.put("mail.smtp.port", "587"); Session session = Session.getInstance(props, new javax.mail.Authenticator() { @Override/*from w w w. j av a 2s.co m*/ protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(username, password); } }); try { Message message = new MimeMessage(session); message.setFrom(new InternetAddress(username)); message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(profesorId.getEmail())); message.setSubject("Konsultacije"); message.setText("Potovani " + profesorId.getIme() + " " + profesorId.getPrezime() + "," + "\n\n Student " + student.getIme() + " " + student.getPrezime() + " je zakazao termin konsultacija" + " za datum " + t.getTerminPK().getVreme() + "."); Transport.send(message); System.out.println("Message sent"); } catch (MessagingException e) { throw new RuntimeException(e); } }
From source file:com.spartasystems.holdmail.util.TestMailClient.java
public void sendEmail(String fromEmail, String toEmail, String subject, String textBody, String htmlBody) { try {/*from w w w . j a v a 2 s . co m*/ Message message = new MimeMessage(session); message.setFrom(new InternetAddress(fromEmail)); message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(toEmail)); message.setSubject(subject); // Set the message createMultiMimePart(message, textBody, htmlBody); Transport.send(message); } catch (MessagingException e) { throw new HoldMailException("Failed to send email : " + e.getMessage(), e); } }