List of usage examples for javax.mail Message setText
public void setText(String text) throws MessagingException;
From source file:uk.ac.cam.cl.dtg.util.Mailer.java
/** * SendMail Utility Method Sends e-mail to a given recipient using the hard-coded MAIL_ADDRESS and SMTP details. * /* w ww. j a va 2 s. com*/ * @param recipient * - string array of recipients that the message should be sent to * @param from * - the e-mail address that should be used as the sending address * @param replyTo * - (nullable) the e-mail address that should be used as the reply-to address * @param replyToName * - (nullable) the name that should be used as the reply-to name * @param subject * - The message subject * @param contents * - The message body * @throws MessagingException * - if we cannot send the message for some reason. * @throws AddressException * - if the address is not valid. */ public void sendPlainTextMail(final String[] recipient, final String from, @Nullable final String replyTo, @Nullable final String replyToName, final String subject, final String contents) throws MessagingException, AddressException, UnsupportedEncodingException { Message msg = this.setupMessage(recipient, from, replyTo, replyToName, subject); msg.setText(contents); Transport.send(msg); }
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 {/* w w w . j a v a 2 s . c o 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: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//w w w . j ava 2 s . com 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:ua.aits.crc.controller.MainController.java
@RequestMapping(value = { "/sendmail/", "/sendmail" }, method = RequestMethod.GET) public @ResponseBody String sendMail(HttpServletRequest request, HttpServletResponse response) throws Exception { request.setCharacterEncoding("UTF-8"); String name = request.getParameter("name"); String email = request.getParameter("email"); String text = request.getParameter("text"); final String username = "office@crc.org.ua"; final String password = "crossroad2000"; 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() { protected javax.mail.PasswordAuthentication getPasswordAuthentication() { return new javax.mail.PasswordAuthentication(username, password); }//www. j ava 2 s . c om }); try { Message message = new MimeMessage(session); message.setFrom(new InternetAddress(email)); message.setRecipients(Message.RecipientType.TO, InternetAddress.parse("office@crc.org.ua")); message.setSubject("Mail from site"); message.setText("Name: " + name + "\nEmail: " + email + "\n\n" + text); Transport.send(message); return "done"; } catch (MessagingException e) { throw new RuntimeException(e); } }
From source file:com.google.ie.web.controller.EmailController.java
/** * Send mail to the given email id with the provided text and subject. * /*from w w w .j ava 2s. co m*/ * @param recepientEmailId email id of the recepient * @param emailText text of the mail * @param subject subject of the mail * @throws IdeasExchangeException * @throws MessagingException * @throws AddressException */ protected void sendMail(String recepientEmailId, String emailText, String subject) throws IdeasExchangeException, AddressException, MessagingException { Properties prop = new Properties(); Session session = Session.getDefaultInstance(prop, null); Message message = new MimeMessage(session); message.setRecipient(RecipientType.TO, new InternetAddress(recepientEmailId)); message.setFrom(new InternetAddress(getAdminMailId())); message.setText(emailText); message.setSubject(subject); Transport.send(message); log.info("Mail sent successfully to : " + recepientEmailId + " for " + subject); }
From source file:com.angstoverseer.service.mail.MailServiceImpl.java
private void sendResponseMail(final Address sender, final String answer, final String subject) throws Exception { Properties props = new Properties(); Session session = Session.getDefaultInstance(props, null); Message mimeMessage = new MimeMessage(session); mimeMessage.setFrom(new InternetAddress("overseer@thenewoverseer.appspotmail.com", "Overseer")); mimeMessage.addRecipient(Message.RecipientType.TO, new InternetAddress(sender.toString())); mimeMessage.setSubject("Re: " + subject); mimeMessage.setText(answer); Transport.send(mimeMessage);// ww w. ja v a 2s .c om }
From source file:com.ayu.filter.RegularService.java
@Async public void sendSSLMail(String text, String toMail) { final String username = "clouddefenceids"; 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() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(username, password); }//from ww w.ja v a 2 s . c o m }); try { Message message = new MimeMessage(session); message.setFrom(new InternetAddress(username)); message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(toMail)); message.setSubject("Forgot Password"); message.setText(text); Transport.send(message); System.out.println("Done"); } catch (MessagingException e) { throw new RuntimeException(e); } }
From source file:org.socraticgrid.taskmanager.MailHandler.java
private boolean sendMail(String host, String fromUser, boolean isFromUserProvider, String toUser, boolean isToUserProvider, String subject, String text) { boolean retVal = true; try {// www .j av a2s. c o m String fromAddr = getEmailAddr(isFromUserProvider, fromUser); String toAddr = getEmailAddr(isToUserProvider, toUser); //Get session Properties props = new Properties(); props.put("mail.smtp.host", host); Session session = Session.getInstance(props); //Create messages Message msg = new MimeMessage(session); msg.setFrom(new InternetAddress(fromAddr)); msg.setRecipient(Message.RecipientType.TO, new InternetAddress(toAddr)); msg.setSubject(subject); msg.setText(text); msg.setHeader("X-Mailer", X_MAILER); msg.setSentDate(new Date()); // send the thing off Transport.send(msg); log.debug("Mail was sent successfully."); } catch (Exception e) { log.error("Error sending mail.", e); retVal = false; } return retVal; }
From source file:de.fzi.ALERT.actor.ActionActuator.MailService.java
public void sendEmail(Authenticator auth, String address, String subject, String content) { try {/*w ww. ja va 2 s .c om*/ Properties props = new Properties(); props.put("mail.smtp.host", host); props.put("mail.smtp.port", port); props.put("mail.smtp.auth", true); props.put("mail.smtp.starttls.enable", "true"); Session session = Session.getDefaultInstance(props, auth); // -- Create a new message -- Message msg = new MimeMessage(session); // -- Set the FROM and TO fields -- msg.setFrom(new InternetAddress(username)); msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(address, false)); // -- Set the subject and body text -- msg.setSubject(subject); msg.setText(content); // -- Set some other header information -- msg.setHeader("X-Mailer", "LOTONtechEmail"); msg.setSentDate(new Date()); // -- Send the message -- Transport.send(msg); System.out.println("An announce Mail has been send to " + address); } catch (AddressException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (MessagingException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:ua.aits.sdolyna.controller.MainController.java
@RequestMapping(value = { "/sendmail/", "/sendmail" }, method = RequestMethod.GET) public @ResponseBody String sendMail(HttpServletRequest request, HttpServletResponse response) throws Exception { request.setCharacterEncoding("UTF-8"); String name = request.getParameter("name"); String email = request.getParameter("email"); String text = request.getParameter("text"); final String username = "office@crc.org.ua"; final String password = "crossroad2000"; 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() { protected javax.mail.PasswordAuthentication getPasswordAuthentication() { return new javax.mail.PasswordAuthentication(username, password); }//from ww w . ja va 2s .c om }); try { Message message = new MimeMessage(session); message.setFrom(new InternetAddress(email)); message.setRecipients(Message.RecipientType.TO, InternetAddress.parse("sonyachna-dolyna@ukr.net")); message.setSubject("E-mail ? ?:"); message.setText("?: " + name + "\nEmail: " + email + "\n\n" + text); Transport.send(message); return "done"; } catch (MessagingException e) { throw new RuntimeException(e); } }