List of usage examples for org.springframework.mail.javamail MimeMessageHelper setFrom
public void setFrom(String from) throws MessagingException
From source file:com.mocktpo.util.EmailUtils.java
public static void sendActivationCode(License lic) { JavaMailSenderImpl sender = new JavaMailSenderImpl(); sender.setHost(GlobalConstants.SMTP_HOST); sender.setUsername(GlobalConstants.SMTP_SENDER_EMAIL); sender.setPassword(GlobalConstants.SMTP_SENDER_PASSWORD); MimeMessage message = sender.createMimeMessage(); MimeMessageHelper helper = new MimeMessageHelper(message); try {/*from www . j a v a2 s .co m*/ helper.setFrom(GlobalConstants.SMTP_SENDER_EMAIL); helper.setBcc(GlobalConstants.SMTP_SENDER_EMAIL); helper.setTo(lic.getEmail()); helper.setSubject(GlobalConstants.LICENSE_EMAIL_SUBJECT); helper.setText(getActivationCode(lic)); } catch (Exception e) { e.printStackTrace(); } sender.send(message); }
From source file:com.netsteadfast.greenstep.util.MailClientUtils.java
public static void send(String from, String to, String cc[], String bcc[], String fileNames[], File files[], String subject, String text) throws MailException, Exception { if (mailSender == null) { throw new Exception("null mailSender!"); }//from ww w . j a v a 2 s. c o m if (StringUtils.isBlank(from) || StringUtils.isBlank(to)) { throw new Exception("from and to is required!"); } if (fileNames != null && files != null) { if (fileNames.length != files.length) { throw new Exception("File parameter error!"); } } MimeMessage message = mailSender.createMimeMessage(); MimeMessageHelper helper = new MimeMessageHelper(message, true, Constants.BASE_ENCODING); helper.setFrom(from); helper.setTo(to.endsWith(";") ? to.substring(0, to.length() - 1) : to); helper.setSubject(subject); helper.setText(text, true); if (null != cc && cc.length > 0) { helper.setCc(cc); } if (null != bcc && bcc.length > 0) { helper.setBcc(bcc); } for (int i = 0; fileNames != null && i < fileNames.length; i++) { helper.addAttachment(fileNames[i], files[i]); } mailSender.send(message); }
From source file:org.apache.niolex.commons.mail.EmailUtil.java
/** * Send an email.//from w ww . ja v a 2 s . c om * ???? * * @param from the email sender * @param tos the email receivers array * @param ccs the carbon copiers array * @param title the email title * @param text the email body * @param attachments the email attachments list * @param priority priority from 1-5 the smaller is higher * @param isHtml is the text in HTML format or not * @param encoding the encoding of email, i.e. "GBK"?"UTF-8" * @throws MailException * @throws MessagingException */ public static void sendMail(String from, String[] tos, String[] ccs, String title, String text, List<Pair<String, InputStreamSource>> attachments, String priority, boolean isHtml, String encoding) throws MailException, MessagingException { MimeMessage mimeMessage = mailSender.createMimeMessage(); MimeMessageHelper messageHelper = new MimeMessageHelper(mimeMessage, true, encoding); messageHelper.setFrom(from); messageHelper.setBcc(from); if (ArrayUtils.isEmpty(tos)) { throw new IllegalArgumentException("<tos> can not be null or empty!"); } else { messageHelper.setTo(tos); } if (!ArrayUtils.isEmpty(ccs)) { messageHelper.setCc(ccs); } messageHelper.setSubject(title); messageHelper.setText(text, isHtml); if (attachments != null) { for (Pair<String, InputStreamSource> pair : attachments) { messageHelper.addAttachment(pair.a, pair.b); } } mimeMessage = messageHelper.getMimeMessage(); if (priority != null) { mimeMessage.addHeader("X-Priority", priority); } mailSender.send(mimeMessage); }
From source file:julie.com.mikaelson.util.EmailSenderUtil.java
synchronized public static boolean sendEmail(String[] toList, String content) { boolean result = false; MimeMessage message = javaMail.createMimeMessage(); MimeMessageHelper messageHelp; try {/*from www . ja v a2 s . com*/ long start = System.currentTimeMillis(); System.out.println("sendEmail invoked "); messageHelp = new MimeMessageHelper(message, true, "UTF-8"); messageHelp.setFrom(emailConfig.getFrom()); messageHelp.setTo(toList); messageHelp.setSubject("Test"); String body = content + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()); messageHelp.setText(body, true); javaMail.send(message); System.out.println("send total time is" + (System.currentTimeMillis() - start)); Thread.sleep(10 * 1000l); } catch (MailException e) { e.printStackTrace(); } catch (MessagingException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } return result; }
From source file:com.rxx.common.util.MailUtil.java
/** * html//ww w . j a va2 s . c om * * @param host * @param port * @param userName * @param password * @param title * @param contenthtml * @param imgs * @param toUser * @throws javax.mail.MessagingException */ public static void sendNews(String host, int port, String userName, String password, String title, String content, List<String> imgs, String[] toUser) throws MessagingException, javax.mail.MessagingException { JavaMailSenderImpl senderImpl = new JavaMailSenderImpl(); // mail server senderImpl.setHost(host); // ,html MimeMessage mailMessage = senderImpl.createMimeMessage(); // boolean,MimeMessageHelpertrue // multipart MimeMessageHelper messageHelper = new MimeMessageHelper(mailMessage, true); // messageHelper.setTo(toUser); messageHelper.setFrom(userName); messageHelper.setSubject(title); // true HTML messageHelper.setText(content, true); int i = 0; for (String imagePath : imgs) { FileSystemResource img = new FileSystemResource(new File(imagePath)); messageHelper.addInline(i + "", img); i++; } senderImpl.setUsername(userName); // ,username senderImpl.setPassword(password); // , password Properties prop = new Properties(); prop.put("mail.smtp.auth", "true"); // true, prop.put("mail.smtp.timeout", "25000"); senderImpl.setJavaMailProperties(prop); // senderImpl.send(mailMessage); // senderImpl.send(mailMessage); }
From source file:com.rxx.common.util.MailUtil.java
/** * html/*from w ww.ja v a 2s. co m*/ * * @param host * @param port * @param userName * @param password * @param title * @param contenthtml * @param fileslist<Map<key:,value:>> * @param toUser * @throws javax.mail.MessagingException */ public static void sendAttached(String host, int port, String userName, String password, String title, String content, List<Map<String, String>> files, String[] toUser) throws MessagingException, javax.mail.MessagingException { JavaMailSenderImpl senderImpl = new JavaMailSenderImpl(); // mail server senderImpl.setHost(host); // ,html MimeMessage mailMessage = senderImpl.createMimeMessage(); // boolean,MimeMessageHelpertrue // multipart true html MimeMessageHelper messageHelper = new MimeMessageHelper(mailMessage, true, "utf-8"); // messageHelper.setTo(toUser); messageHelper.setFrom(userName); messageHelper.setSubject(title); // true HTML messageHelper.setText(content, true); for (Map<String, String> filePath : files) { Iterator<String> it = filePath.keySet().iterator(); String fileName = it.next(); FileSystemResource file = new FileSystemResource(new File(filePath.get(fileName))); // messageHelper.addAttachment(fileName, file); } senderImpl.setUsername(userName); // ,username senderImpl.setPassword(password); // , password Properties prop = new Properties(); prop.put("mail.smtp.auth", "true"); // true, prop.put("mail.smtp.timeout", "25000"); senderImpl.setJavaMailProperties(prop); // senderImpl.send(mailMessage); }
From source file:com.rxx.common.util.MailUtil.java
/** * html/*w w w . j ava 2 s . c o m*/ * * @param host * @param port * @param userName * @param password * @param title * @param contenthtml * @param toUser * @throws javax.mail.MessagingException */ public static void sendHtml(String host, int port, String userName, String password, String title, String content, String[] toUser) { JavaMailSenderImpl senderImpl = new JavaMailSenderImpl(); // mail server senderImpl.setHost(host); senderImpl.setPort(port); // ,html MimeMessage mailMessage = senderImpl.createMimeMessage(); try { MimeMessageHelper messageHelper = new MimeMessageHelper(mailMessage, true, "UTF-8"); try { // messageHelper.setTo(toUser); messageHelper.setFrom(userName); messageHelper.setSubject(title); // true HTML messageHelper.setText(content, true); } catch (javax.mail.MessagingException e) { // TODO Auto-generated catch block e.printStackTrace(); } senderImpl.setUsername(userName); // ,username senderImpl.setPassword(password); // , password Properties prop = new Properties(); prop.put("mail.smtp.auth", "true"); // true, prop.put("mail.smtp.timeout", "25000"); senderImpl.setJavaMailProperties(prop); // senderImpl.send(mailMessage); } catch (javax.mail.MessagingException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } }
From source file:org.khmeracademy.btb.auc.pojo.utilities.VerifyCode_sevice.java
public void sendComfirmation(User user) throws MailException, MessagingException { MimeMessage message = javaMailSender.createMimeMessage(); MimeMessageHelper mail = new MimeMessageHelper(message, true); mail.setFrom("kuylim.auction@gmail.com"); mail.setTo(user.getEmail());//ww w. j av a2s . c o m mail.setSubject("Verify Email"); mail.setText("<html>" + "<body>" + "<p>Dear, " + user.getFirstname() + "</p>" + "<p>Congratulation! You have register to K-Auction. Click <a href='http://localhost:2222/verifykey/" + user.getVerifyKey() + "'>here</a>" + " to activate your account.</p>" + "<p>If this is not you. please ignore this email.</p>" + "<p>Regard,</p>" + "<p>K-Auction Team.</p>" + "</body>" + "</html>", true); javaMailSender.send(message); }
From source file:org.revo.controller.Mymail.java
public void sendMail(String from, String to, String subject, String contents) { MimeMessage message = mailSender.createMimeMessage(); try {/*from w ww . j a v a 2s . co m*/ MimeMessageHelper helper = new MimeMessageHelper(message, true); helper.setFrom(from); helper.setTo(to); helper.setSubject(subject); helper.setText(contents); } catch (MessagingException e) { throw new MailParseException(e); } mailSender.send(message); }
From source file:org.openlmis.notification.service.NotificationService.java
/** * Send an email notification.// ww w .ja va 2s.c o m * * @param from email address of the sender * @param to email address of the receiver * @param subject subject of the email * @param content content of the email * @throws MessagingException a generic messaging exception */ public void sendNotification(String from, String to, String subject, String content) throws MessagingException { if (content == null) { throw new MessagingException("Content must not be null"); } MimeMessage message = mailSender.createMimeMessage(); MimeMessageHelper helper = new MimeMessageHelper(message, false); helper.setFrom(from); helper.setTo(to); helper.setSubject(subject); helper.setText(content); mailSender.send(message); }