List of usage examples for org.springframework.mail.javamail MimeMessageHelper setText
public void setText(String text) 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 w ww . 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.yoncabt.ebr.executor.YoncaMailSender.java
public void send(String to, String text, Map<String, byte[]> attachments) throws MessagingException { MimeMessage mm = mailSender.createMimeMessage(); MimeMessageHelper mmh = new MimeMessageHelper(mm, true); mmh.setTo(to);//w ww.j a v a 2s . c o m mmh.setText(text); for (Map.Entry<String, byte[]> entrySet : attachments.entrySet()) { String key = entrySet.getKey(); byte[] value = entrySet.getValue(); ByteArrayResource isr = new ByteArrayResource(value); mmh.addAttachment(key, isr); } mailSender.send(mm); }
From source file:org.openlmis.notification.service.NotificationService.java
/** * Send an email notification.//w w w. j av a2 s. 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); }
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 ww w. java 2 s. c o 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:ca.airspeed.demo.testingemail.EmailService.java
public void sendSimpleEmail(InternetAddress to, String subject, String textBody) throws MessagingException { notNull(mailSender, String.format("Check your configuration, I need an instance of %s.", JavaMailSender.class.getCanonicalName())); MimeMessage message = mailSender.createMimeMessage(); MimeMessageHelper helper = new MimeMessageHelper(message, true); helper.setTo(to);//w w w.j a va2 s. co m helper.setFrom(senderAddress); helper.setSubject(subject); helper.setText(textBody); mailSender.send(message); }
From source file:ca.airspeed.demo.testingemail.EmailService.java
public void sendWithAttachments(InternetAddress to, String subject, String textBody, List<FileSystemResource> fileList) throws MessagingException { notNull(mailSender, String.format("Check your configuration, I need an instance of %s.", JavaMailSender.class.getCanonicalName())); MimeMessage message = mailSender.createMimeMessage(); MimeMessageHelper helper = new MimeMessageHelper(message, true); helper.setTo(to);/*from w w w.j a va 2 s . c o m*/ helper.setFrom(senderAddress); helper.setSubject(subject); helper.setText(textBody); for (FileSystemResource resource : fileList) { helper.addAttachment(resource.getFilename(), resource.getFile()); } mailSender.send(message); }
From source file:com.rinxor.cloud.service.mail.Mailer.java
public void sendMail(String from, String to, String subject, String msg) { MimeMessage message = mailSender.createMimeMessage(); try {/* w w w. j a v a2 s. c o m*/ MimeMessageHelper helper = new MimeMessageHelper(message, true); helper.setFrom(from); helper.setTo(to); helper.setSubject(subject); helper.setText(String.format(msg)); //FileSystemResource file = new FileSystemResource("C:\\log.txt"); //helper.addAttachment(file.getFilename(), file); } catch (MessagingException e) { throw new MailParseException(e); } mailSender.send(message); }
From source file:org.apigw.authserver.web.controller.AlertController.java
public @ResponseBody String alert(@RequestBody Map<String, Object> alert) { String clientId, state;//from w ww . j a v a 2 s.c o m if (alert.containsKey("categories") && alert.get("categories") instanceof List) { List<String> categories = (List<String>) alert.get("categories"); log.info("cat: " + categories); clientId = categories.get(0); } else { throw new RuntimeException("No categories found"); } for (String k : alert.keySet()) { log.info(k + ": " + alert.get(k)); } Application app = appManagement.getApplicationByClientId(clientId); if (app != null) { String email = app.getEmail(); try { MimeMessage message = sender.createMimeMessage(); MimeMessageHelper helper = new MimeMessageHelper(message); helper.setTo(email); helper.setSubject("alert"); helper.setText("text"); sender.send(message); } catch (Exception e) { log.error("Caught exception while trying to send an email", e); } } return ""; }
From source file:com.gisgraphy.service.MailEngine.java
/** * Convenience method for sending messages with attachments. * //from w w w. ja va2s .c o m * @param recipients * array of e-mail addresses * @param sender * e-mail address of sender * @param resource * attachment from classpath * @param bodyText * text in e-mail * @param subject * subject of e-mail * @param attachmentName * name for attachment * @throws MessagingException * thrown when can't communicate with SMTP server */ public void sendMessage(String[] recipients, String sender, ClassPathResource resource, String bodyText, String subject, String attachmentName) throws MessagingException { MimeMessage message = ((JavaMailSenderImpl) mailSender).createMimeMessage(); // use the true flag to indicate you need a multipart message MimeMessageHelper helper = new MimeMessageHelper(message, true); helper.setTo(recipients); helper.setFrom(sender); helper.setText(bodyText); helper.setSubject(subject); helper.addAttachment(attachmentName, resource); ((JavaMailSenderImpl) mailSender).send(message); }
From source file:com.abcd.employeemaven.common.MailEmployee.java
public void Mailing(String name, String content) throws MessagingException, MailParseException { MimeMessage message = javaMailSender.createMimeMessage(); MimeMessageHelper helper = new MimeMessageHelper(message, true); helper.setFrom(simpleMailMessage.getFrom()); helper.setTo(simpleMailMessage.getTo()); helper.setSubject(simpleMailMessage.getSubject()); helper.setText(String.format(simpleMailMessage.getText(), name, content)); // FileSystemResource file = new FileSystemResource("C:\\log.txt"); // helper.addAttachment(file.getFilename(), file); }