List of usage examples for org.springframework.mail.javamail MimeMessageHelper setTo
public void setTo(String[] to) throws MessagingException
From source file:be.roots.taconic.pricingguide.service.MailServiceImpl.java
@Override public void sendMail(Contact contact, byte[] pricingGuide) throws MessagingException { final MimeMessageHelper helper = new MimeMessageHelper(javaMailSender.createMimeMessage(), true); helper.setFrom(fromEmail);//from w ww . j av a2s . com if (StringUtils.isEmpty(testEmail)) { helper.setTo(contact.getEmail()); } else { helper.setTo(testEmail.split(",")); } if (!StringUtils.isEmpty(bccEmail)) { helper.setBcc(bccEmail.split(",")); } helper.setSubject("Your " + documentTitle); final String body = "Dear " + contact.getFullName() + ",<br>" + "<br>" + "Your " + documentTitle + " is attached.<br>" + "<br>" + "Please <a href=\"http:www.taconic.com/customer-service/contact-us\">contact us</a> for any additional information.<br>" + "<br>" + "Taconic Biosciences, Inc.<br>" + "One Hudson City Centre<br>" + "Hudson, New York 12534<br>" + "North America +1 888 822-6642<br>" + "Europe +45 70 23 04 05<br>" + "info@taconic.com<br>" + "www.taconic.com"; helper.setText(body, true); helper.addAttachment(documentFileName, new ByteArrayResource(pricingGuide)); javaMailSender.send(helper.getMimeMessage()); }
From source file:com.pamarin.income.controller.RegisterAccountCtrl.java
private void sendEmail(final String activateCode) { mailSender.send(new MailCallback() { @Override//from www.j ava 2s . co m public void execute(MimeMessageHelper helper) throws Exception { helper.setSubject("?" + app.getName()); helper.setTo(getEmail()); helper.setText( "? " + "???? " + UrlUtils.buildHostUrl() + "/register/activate/?code=" + activateCode); } }); }
From source file:gov.nih.nci.cabig.caaers.web.admin.DiagnosticsController.java
private boolean testSmtp(DiagnosticsCommand diagnosticsCommand) { boolean testResult = false; try {// w ww .j a v a2s.c o m MimeMessage message = caaersJavaMailSender.createMimeMessage(); message.setSubject("Test mail from caAERS Diagnostics"); message.setFrom(new InternetAddress("caaers.app@gmail.com")); // use the true flag to indicate you need a multipart message MimeMessageHelper helper = new MimeMessageHelper(message, true); String fromEmail = configuration.get(Configuration.SYSTEM_FROM_EMAIL); if (fromEmail == null) fromEmail = "admin@semanticbits.com"; helper.setTo(fromEmail); caaersJavaMailSender.send(message); testResult = true; } catch (Exception e) { //log.error(" Error in sending email , please check the confiuration " + e); diagnosticsCommand.setSmtpException(e); testResult = false; } return testResult; }
From source file:com.gcrm.util.mail.MailService.java
public void sendHtmlMail(String from, String[] to, String subject, String text, String[] fileNames, File[] files) throws Exception { List<EmailSetting> emailSettings = baseService.getAllObjects(EmailSetting.class.getSimpleName()); EmailSetting emailSetting = null;//from w ww. j a v a 2 s .co m if (emailSettings != null && emailSettings.size() > 0) { emailSetting = emailSettings.get(0); } else { return; } if (from == null) { from = emailSetting.getFrom_address(); } Session mailSession = createSmtpSession(emailSetting); if (mailSession != null) { Transport transport = mailSession.getTransport(); MimeMessage msg = new MimeMessage(mailSession); MimeMessageHelper helper = new MimeMessageHelper(msg, true, "utf-8"); helper.setFrom(from); helper.setTo(to); helper.setSubject(subject); helper.setText(text, true); if (fileNames != null && files != null) { String fileName = null; File file = null; for (int i = 0; i < fileNames.length; i++) { fileName = fileNames[i]; file = files[i]; if (fileName != null && file != null) { helper.addAttachment(fileName, file); } } } transport.connect(); transport.sendMessage(msg, msg.getRecipients(Message.RecipientType.TO)); } }
From source file:org.appverse.web.framework.backend.api.services.integration.impl.live.MailIntegrationServiceImpl.java
@Override @SuppressWarnings("unchecked") public void sendMail(String from, String[] to, String[] copyTo, String subject, String templateLocation, Map model) throws Exception { MimeMessage message = mailSender.createMimeMessage(); MimeMessageHelper helper = new MimeMessageHelper(message, true); helper.setFrom(from);// www.j ava 2 s. c o m helper.setTo(to); if (copyTo != null) { helper.setCc(copyTo); } helper.setSubject(subject); String text = VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, ENCODING, templateLocation, model); helper.setText(text, true); try { this.mailSender.send(message); } catch (MailSendException sendMailException) { Exception[] messageExceptions = sendMailException.getMessageExceptions(); for (Exception messageException : messageExceptions) { if (messageException instanceof SendFailedException) { SendFailedException sendFailedException = (SendFailedException) messageException; if (sendFailedException.getMessage().equals(INVALID_ADDRESSES)) { Address[] invalidAddresses = sendFailedException.getInvalidAddresses(); List<String> invalidAddressList = new ArrayList<String>(); for (Address invalidAddress : invalidAddresses) { String invalidAddressString = invalidAddress.toString(); invalidAddressList.add(invalidAddressString); } List<String> validToAdressesList = new ArrayList<String>(); if (to != null && to.length > 0) { for (String address : to) { if (!invalidAddressList.contains(address)) { validToAdressesList.add(address); } } } List<String> validCopyToAdressesList = new ArrayList<String>(); if (copyTo != null && copyTo.length > 0) { for (String address : copyTo) { if (!invalidAddressList.contains(address)) { validCopyToAdressesList.add(address); } } } String[] validToAdressesArray = new String[validToAdressesList.size()]; validToAdressesList.toArray(validToAdressesArray); helper.setTo(validToAdressesList.toArray(validToAdressesArray)); String[] validCopyToAdressesArray = new String[validCopyToAdressesList.size()]; validCopyToAdressesList.toArray(validCopyToAdressesArray); helper.setCc(validCopyToAdressesList.toArray(validCopyToAdressesArray)); for (String invalidAddress : invalidAddressList) { logger.error("Mail not sended to " + invalidAddress + "due its a invalid address"); } this.mailSender.send(message); } } } } }
From source file:ru.mystamps.web.service.MailServiceImpl.java
@SuppressWarnings("PMD.UseObjectForClearerAPI") private void sendMail(final String email, final String subject, final String text, final String tag) { try {//from ww w .ja v a2 s. com // We're using MimeMessagePreparator only because of its capability of adding headers. // Otherwise we would use SimpleMailMessage class. MimeMessagePreparator preparator = new MimeMessagePreparator() { @Override @SuppressWarnings("PMD.SignatureDeclareThrowsException") public void prepare(MimeMessage mimeMessage) throws Exception { MimeMessageHelper message = new MimeMessageHelper(mimeMessage, "UTF-8"); message.setValidateAddresses(true); message.setTo(email); message.setFrom(new InternetAddress(robotEmail, "My Stamps", "UTF-8")); message.setSubject(subject); message.setText(text); // see: http://documentation.mailgun.com/user_manual.html#sending-via-smtp message.getMimeMessage().addHeader("X-Mailgun-Tag", tag); if (testMode) { message.getMimeMessage().addHeader("X-Mailgun-Drop-Message", "yes"); } } }; mailer.send(preparator); } catch (MailException ex) { throw new EmailSendingException("Can't send mail to e-mail " + email, ex); } }
From source file:org.appverse.web.framework.backend.api.services.integration.impl.live.MailIntegrationServiceImpl.java
@SuppressWarnings("unchecked") @Override//from w w w .j a va 2 s .c om public void sendMail(String from, String[] to, String[] copyTo, String subject, String templateLocation, Map model, ArrayList<AttachmentDTO> attachments) throws Exception { MimeMessage message = mailSender.createMimeMessage(); MimeMessageHelper helper = new MimeMessageHelper(message, true); helper.setFrom(from); helper.setTo(to); if (copyTo != null) { helper.setCc(copyTo); } helper.setSubject(subject); String text = VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, ENCODING, templateLocation, model); helper.setText(text, true); for (AttachmentDTO attachmentDTO : attachments) { helper.addAttachment(attachmentDTO.getAttachmentName(), attachmentDTO.getAttachment()); } try { this.mailSender.send(message); } catch (MailSendException sendMailException) { Exception[] messageExceptions = sendMailException.getMessageExceptions(); for (Exception messageException : messageExceptions) { if (messageException instanceof SendFailedException) { SendFailedException sendFailedException = (SendFailedException) messageException; if (sendFailedException.getMessage().equals(INVALID_ADDRESSES)) { Address[] invalidAddresses = sendFailedException.getInvalidAddresses(); List<String> invalidAddressList = new ArrayList<String>(); for (Address invalidAddress : invalidAddresses) { String invalidAddressString = invalidAddress.toString(); invalidAddressList.add(invalidAddressString); } List<String> validToAdressesList = new ArrayList<String>(); if (to != null && to.length > 0) { for (String address : to) { if (!invalidAddressList.contains(address)) { validToAdressesList.add(address); } } } List<String> validCopyToAdressesList = new ArrayList<String>(); if (copyTo != null && copyTo.length > 0) { for (String address : copyTo) { if (!invalidAddressList.contains(address)) { validCopyToAdressesList.add(address); } } } String[] validToAdressesArray = new String[validToAdressesList.size()]; validToAdressesList.toArray(validToAdressesArray); helper.setTo(validToAdressesList.toArray(validToAdressesArray)); String[] validCopyToAdressesArray = new String[validCopyToAdressesList.size()]; validCopyToAdressesList.toArray(validCopyToAdressesArray); helper.setCc(validCopyToAdressesList.toArray(validCopyToAdressesArray)); for (String invalidAddress : invalidAddressList) { logger.error("Mail not sended to " + invalidAddress + "due its a invalid address"); } this.mailSender.send(message); } } } } }
From source file:cz.zcu.kiv.eegdatabase.webservices.rest.user.UserServiceImpl.java
/** * Method for sending registration confirmation email. * * @param registrationPath path to registration confirmation page * @param plainPassword password in plain text * @param user created user object * @param locale locale/*from w ww .j ava 2 s. c om*/ * @throws MailException error during sending mail * @throws MessagingException error during sending mail */ private void sendRegistrationConfirmMail(String registrationPath, String plainPassword, Person user, Locale locale) throws MailException, MessagingException { log.debug("Creating email content"); StringBuilder sb = new StringBuilder(); String login = "<b>" + user.getUsername() + "</b>"; sb.append("<html><body>"); sb.append("<h4>"); sb.append(messageSource.getMessage("registration.email.welcome", null, locale)); sb.append("</h4>"); sb.append("<p>"); sb.append(messageSource.getMessage("registration.email.body.yourLogin", new String[] { login }, locale)); sb.append("</p>"); sb.append("<p>"); sb.append(messageSource.getMessage("registration.email.body.yourPassword", new String[] { plainPassword }, locale)); sb.append("</p>"); sb.append("<p>"); sb.append(messageSource.getMessage("registration.email.body.clickToRegister", null, locale)); sb.append("<br/>"); String confirmURL = registrationPath + user.getAuthenticationHash(); sb.append("<a href=\"").append(confirmURL).append("\">").append(confirmURL).append("</a>"); sb.append("</p>"); sb.append("</body></html>"); String emailSubject = messageSource.getMessage("registration.email.subject", null, locale); MimeMessage mimeMessage = mailSender.createMimeMessage(); MimeMessageHelper message = new MimeMessageHelper(mimeMessage); message.setFrom(mailMessage.getFrom()); message.setTo(user.getEmail()); message.setSubject(emailSubject); message.setText(sb.toString(), true); mailSender.send(mimeMessage); }
From source file:com.gcrm.util.mail.MailService.java
public void sendSimpleMail(String toAddress) throws Exception { List<EmailSetting> emailSettings = baseService.getAllObjects(EmailSetting.class.getSimpleName()); EmailSetting emailSetting = null;/*from ww w .j ava 2 s . c o m*/ if (emailSettings != null && emailSettings.size() > 0) { emailSetting = emailSettings.get(0); } else { return; } Session mailSession = this.createSmtpSession(emailSetting); if (mailSession != null) { Transport transport = mailSession.getTransport(); MimeMessage msg = new MimeMessage(mailSession); MimeMessageHelper helper = new MimeMessageHelper(msg, true, "utf-8"); helper.setFrom(emailSetting.getFrom_address()); helper.setTo(toAddress); helper.setSubject("Test Mail From " + emailSetting.getFrom_name()); helper.setText("This is test mail from " + emailSetting.getFrom_name(), true); transport.connect(); transport.sendMessage(msg, msg.getRecipients(Message.RecipientType.TO)); } }
From source file:com.gcrm.util.mail.MailService.java
public void sendSystemSimpleMail(String toAddress, String subject, String text) throws Exception { List<EmailSetting> emailSettings = baseService.getAllObjects(EmailSetting.class.getSimpleName()); EmailSetting emailSetting = null;// w ww .j a v a 2 s.com if (emailSettings != null && emailSettings.size() > 0) { emailSetting = emailSettings.get(0); } else { return; } Session mailSession = this.createSmtpSession(emailSetting); if (mailSession != null) { Transport transport = mailSession.getTransport(); MimeMessage msg = new MimeMessage(mailSession); MimeMessageHelper helper = new MimeMessageHelper(msg, true, "utf-8"); helper.setFrom(emailSetting.getFrom_address()); helper.setTo(toAddress); helper.setSubject(subject); helper.setText(text, true); transport.connect(); transport.sendMessage(msg, msg.getRecipients(Message.RecipientType.TO)); } }