Java Code Examples for org.springframework.mail.javamail.MimeMessageHelper#setReplyTo()

The following examples show how to use org.springframework.mail.javamail.MimeMessageHelper#setReplyTo() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MailServiceImpl.java    From olat with Apache License 2.0 6 votes vote down vote up
@Override
public void sendMailWithAttachments(final TemplateWithAttachmentMailTO template) throws MailException {
    MimeMessagePreparator preparator = new MimeMessagePreparator() {
        @Override
        public void prepare(MimeMessage mimeMessage) throws Exception {
            MimeMessageHelper message = new MimeMessageHelper(mimeMessage, true);

            message.addTo(template.getToMailAddress());
            message.setFrom(template.getFromMailAddress());
            message.setSubject(template.getSubject());
            if (template.hasCcMailAddress()) {
                message.setCc(template.getCcMailAddress());
            }
            if (template.hasReplyTo()) {
                message.setReplyTo(template.getReplyTo());
            }

            // add attachments if any
            List<File> attachments = template.getAttachments();
            for (File file : attachments) {
                message.addAttachment(file.getName(), file);
            }

            String text = VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, template.getTemplateLocation(), template.getTemplateProperties());
            message.setText(text, true);
            message.setValidateAddresses(true);
        }
    };
    this.mailSender.send(preparator);
}
 
Example 2
Source File: EmailNotificationServiceImpl.java    From podcastpedia-web with MIT License 6 votes vote down vote up
public void sendContactNotification(final ContactForm contactForm) {
      MimeMessagePreparator preparator = new MimeMessagePreparator() {
        @SuppressWarnings({ "rawtypes", "unchecked" })
		public void prepare(MimeMessage mimeMessage) throws Exception {
             MimeMessageHelper message = new MimeMessageHelper(mimeMessage);
             message.setTo(configService.getValue("EMAIL_TO_CONTACT_MESSAGE"));
             message.setBcc("[email protected]");
             message.setFrom(new InternetAddress(contactForm.getEmail()));
             message.setSubject("New contact message " + contactForm.getTopic());
             message.setReplyTo(contactForm.getEmail());
             message.setSentDate(new Date());
             Map model = new HashMap();	             
             model.put("newMessage", contactForm);
             
             String text = VelocityEngineUtils.mergeTemplateIntoString(
                velocityEngine, "velocity/newContactMessageToAdmin.vm", "UTF-8", model);
             message.setText(text, true);
          }
       };
       this.mailSender.send(preparator);	  
}
 
Example 3
Source File: UserRegistrationEmailTransformer.java    From website with GNU Affero General Public License v3.0 5 votes vote down vote up
@Transformer
public MimeMessage transform(final User user) throws MessagingException, IOException {
	MimeMessage message = getEmailSender().createMimeMessage();
	MimeMessageHelper helper = new MimeMessageHelper(message);
	helper.setTo(toEmail);
	helper.setFrom(getDefaultFromAddress(), getDefaultFromName());
	helper.setReplyTo(getDefaultFromAddress());
	helper.setSubject(getSubject());
	Map<String, Object> model = buildModel(user);
	helper.setText(getText(model), true);
	return message;
}
 
Example 4
Source File: PaidPublisherPaymentRequestEmailTransformer.java    From website with GNU Affero General Public License v3.0 5 votes vote down vote up
@Transformer
  public MimeMessage transform(final PublisherPaymentRequest publisherPaymentRequest) throws MessagingException, IOException {
MimeMessage message = getEmailSender().createMimeMessage();
  	MimeMessageHelper helper = new MimeMessageHelper(message);
  	helper.setTo(publisherPaymentRequest.getUser().getEmail());
  	helper.setFrom(getDefaultFromAddress(), getDefaultFromName());
  	helper.setReplyTo(getDefaultFromAddress());
  	helper.setSubject(getSubject());
  	Map<String, Object> model = buildModel(publisherPaymentRequest);
  	helper.setText(getText(model), true);
  	return message;
  }
 
Example 5
Source File: ReopenUserEmailTransformer.java    From website with GNU Affero General Public License v3.0 5 votes vote down vote up
@Transformer
public MimeMessage transform(final User user) throws MessagingException, IOException {
	MimeMessage message = getEmailSender().createMimeMessage();
	MimeMessageHelper helper = new MimeMessageHelper(message);
	helper.setTo(user.getEmail());
	helper.setFrom(getDefaultFromAddress(), getDefaultFromName());
	helper.setReplyTo(getDefaultFromAddress());
	helper.setSubject(getSubject());
	Map<String, Object> model = buildModel(user);
	helper.setText(getText(model), true);
	return message;
}
 
Example 6
Source File: CloseUserEmailTransformer.java    From website with GNU Affero General Public License v3.0 5 votes vote down vote up
@Transformer
public MimeMessage transform(final User user) throws MessagingException, IOException {
	MimeMessage message = getEmailSender().createMimeMessage();
	MimeMessageHelper helper = new MimeMessageHelper(message);
	helper.setTo(user.getEmail());
	helper.setFrom(getDefaultFromAddress(), getDefaultFromName());
	helper.setReplyTo(getDefaultFromAddress());
	helper.setSubject(getSubject());
	Map<String, Object> model = buildModel(user);
	helper.setText(getText(model), true);
	return message;
}
 
Example 7
Source File: PublisherEarningReminderEmailTransformer.java    From website with GNU Affero General Public License v3.0 5 votes vote down vote up
@Transformer
  public MimeMessage transform(final User user) throws MessagingException, IOException {
MimeMessage message = getEmailSender().createMimeMessage();
  	MimeMessageHelper helper = new MimeMessageHelper(message);
  	helper.setTo(user.getEmail());
  	helper.setFrom(getDefaultFromAddress(), getDefaultFromName());
  	helper.setReplyTo(getDefaultFromAddress());
  	helper.setSubject(getSubject());
  	Map<String, Object> model = buildModel(user);
  	helper.setText(getText(model), true);
  	return message;
  }
 
Example 8
Source File: PaperightCreditTransactionPaymentReceivedEmailTransformer.java    From website with GNU Affero General Public License v3.0 5 votes vote down vote up
@Transformer
   public MimeMessage transform(final PaperightCreditTransaction transaction) throws MessagingException, IOException {
	MimeMessage message = getEmailSender().createMimeMessage();
   	MimeMessageHelper helper = new MimeMessageHelper(message);
   	helper.setTo(transaction.getUser().getEmail());
   	helper.setFrom(getDefaultFromAddress(), getDefaultFromName());
   	helper.setReplyTo(getDefaultFromAddress());
   	helper.setSubject(getSubject());
   	Map<String, Object> model = buildModel(transaction);
   	helper.setText(getText(model), true);
   	return message;
}
 
Example 9
Source File: ResetPasswordEmailTransformer.java    From website with GNU Affero General Public License v3.0 5 votes vote down vote up
@Transformer
public MimeMessage transform(final ResetPassword resetPassword) throws MessagingException, IOException {
	MimeMessage message = getEmailSender().createMimeMessage();
	MimeMessageHelper helper = new MimeMessageHelper(message);
	helper.setTo(resetPassword.getUser().getEmail());
	helper.setFrom(getDefaultFromAddress(), getDefaultFromName());
	helper.setReplyTo(getDefaultFromAddress());
	helper.setSubject(getSubject());
	Map<String, Object> model = buildModel(resetPassword);
	helper.setText(getText(model), true);
	return message;
}
 
Example 10
Source File: UpdateEmailNewEmailTransformer.java    From website with GNU Affero General Public License v3.0 5 votes vote down vote up
@Transformer
public MimeMessage transform(final UpdateEmail updateEmail) throws MessagingException, IOException {
	MimeMessage message = getEmailSender().createMimeMessage();
	MimeMessageHelper helper = new MimeMessageHelper(message);
	helper.setTo(updateEmail.getUser().getEmail());
	helper.setFrom(getDefaultFromAddress(), getDefaultFromName());
	helper.setReplyTo(getDefaultFromAddress());
	helper.setSubject(getSubject());
	Map<String, Object> model = buildModel(updateEmail);
	helper.setText(getText(model), true);
	return message;
}
 
Example 11
Source File: ActivateUserEmailTransformer.java    From website with GNU Affero General Public License v3.0 5 votes vote down vote up
@Transformer
public MimeMessage transform(final User user) throws MessagingException, IOException {
	MimeMessage message = getEmailSender().createMimeMessage();
	MimeMessageHelper helper = new MimeMessageHelper(message);
	helper.setTo(user.getEmail());
	helper.setFrom(getDefaultFromAddress(), getDefaultFromName());
	helper.setReplyTo(getDefaultFromAddress());
	helper.setSubject(getSubject());
	Map<String, Object> model = buildModel(user);
	helper.setText(getText(model), true);
	return message;
}
 
Example 12
Source File: NewUserEmailTransformer.java    From website with GNU Affero General Public License v3.0 5 votes vote down vote up
@Transformer
public MimeMessage transform(final User user) throws MessagingException, IOException {
	MimeMessage message = getEmailSender().createMimeMessage();
	MimeMessageHelper helper = new MimeMessageHelper(message);
	helper.setTo(user.getEmail());
	helper.setFrom(getDefaultFromAddress(), getDefaultFromName());
	helper.setReplyTo(getDefaultFromAddress());
	helper.setSubject(getSubject());
	Map<String, Object> model = buildModel(user);
	helper.setText(getText(model), true);
	return message;
}
 
Example 13
Source File: MailService.java    From eds-starter6-jpa with Apache License 2.0 5 votes vote down vote up
@Async
public void sendHtmlMessage(String from, String to, String subject, String text)
		throws MessagingException {
	MimeMessage message = this.mailSender.createMimeMessage();
	MimeMessageHelper helper = new MimeMessageHelper(message);
	helper.setFrom(this.defaultSender);
	helper.setTo(to);
	helper.setReplyTo(from);
	helper.setText(text, true);
	helper.setSubject(subject);

	this.mailSender.send(message);
}
 
Example 14
Source File: LicencePurchaseEmailTransformer.java    From website with GNU Affero General Public License v3.0 5 votes vote down vote up
@Transformer
public MimeMessage transform(final LicencePurchaseEmail licencePurchaseEmail) throws MessagingException, IOException {
	MimeMessage message = getEmailSender().createMimeMessage();
	MimeMessageHelper helper = new MimeMessageHelper(message);
	helper.setTo(licencePurchaseEmail.getUser().getEmail());
	helper.setFrom(getDefaultFromAddress(), getDefaultFromName());
	helper.setReplyTo(getDefaultFromAddress());
	helper.setSubject(getSubject());
	Map<String, Object> model = buildModel(licencePurchaseEmail);
	helper.setText(getText(model), true);
	return message;
}
 
Example 15
Source File: SuggestBookEmailTransformer.java    From website with GNU Affero General Public License v3.0 5 votes vote down vote up
@Transformer
  public MimeMessage transform(final SuggestBook suggestBook) throws MessagingException, IOException {
MimeMessage message = getEmailSender().createMimeMessage();
  	MimeMessageHelper helper = new MimeMessageHelper(message);
  	helper.setTo(getDefaultToAddress());
  	helper.setFrom(suggestBook.getEmail(), suggestBook.getName());
  	helper.setReplyTo(suggestBook.getEmail());
  	helper.setSubject(getSubject());
  	Map<String, Object> model = buildModel(suggestBook);
  	helper.setText(getText(model), true);
  	return message;
  }
 
Example 16
Source File: CancelPublisherPaymentRequestEmailTransformer.java    From website with GNU Affero General Public License v3.0 5 votes vote down vote up
@Transformer
  public MimeMessage transform(final PublisherPaymentRequest publisherPaymentRequest) throws MessagingException, IOException {
MimeMessage message = getEmailSender().createMimeMessage();
  	MimeMessageHelper helper = new MimeMessageHelper(message);
  	helper.setTo(getDefaultToAddress());
  	helper.setFrom(publisherPaymentRequest.getUser().getEmail(), publisherPaymentRequest.getUser().getCompany().getName());
  	helper.setReplyTo(publisherPaymentRequest.getUser().getEmail());
  	helper.setSubject(getSubject());
  	Map<String, Object> model = buildModel(publisherPaymentRequest);
  	helper.setText(getText(model), true);
  	return message;
  }
 
Example 17
Source File: UpdateEmailOldEmailTransformer.java    From website with GNU Affero General Public License v3.0 5 votes vote down vote up
@Transformer
public MimeMessage transform(final UpdateEmail updateEmail) throws MessagingException, IOException {
	MimeMessage message = getEmailSender().createMimeMessage();
	MimeMessageHelper helper = new MimeMessageHelper(message);
	helper.setTo(updateEmail.getOldEmail());
	helper.setFrom(getDefaultFromAddress(), getDefaultFromName());
	helper.setReplyTo(getDefaultFromAddress());
	helper.setSubject(getSubject());
	Map<String, Object> model = buildModel(updateEmail);
	helper.setText(getText(model), true);
	return message;
}
 
Example 18
Source File: ContactUsEmailTransformer.java    From website with GNU Affero General Public License v3.0 5 votes vote down vote up
@Transformer
public MimeMessage transform(final ContactMessage contactMessage) throws MessagingException, IOException {
	MimeMessage message = getEmailSender().createMimeMessage();
	MimeMessageHelper helper = new MimeMessageHelper(message);
	helper.setTo(getDefaultToAddress());
	helper.setFrom(contactMessage.getEmail(), contactMessage.getName());
	helper.setReplyTo(contactMessage.getEmail());
	helper.setSubject(contactMessage.getSubject());
	Map<String, Object> model = buildModel(contactMessage);
	helper.setText(getText(model), true);
	return message;
}
 
Example 19
Source File: PublisherPaymentRequestEmailTransformer.java    From website with GNU Affero General Public License v3.0 5 votes vote down vote up
@Transformer
  public MimeMessage transform(final PublisherPaymentRequest publisherPaymentRequest) throws MessagingException, IOException {
MimeMessage message = getEmailSender().createMimeMessage();
  	MimeMessageHelper helper = new MimeMessageHelper(message);
  	helper.setTo(getDefaultToAddress());
  	helper.setFrom(publisherPaymentRequest.getUser().getEmail(), publisherPaymentRequest.getUser().getCompany().getName());
  	helper.setReplyTo(publisherPaymentRequest.getUser().getEmail());
  	helper.setSubject(getSubject());
  	Map<String, Object> model = buildModel(publisherPaymentRequest);
  	helper.setText(getText(model), true);
  	return message;
  }
 
Example 20
Source File: JavaMailAgent.java    From kaif with Apache License 2.0 5 votes vote down vote up
public void prepare(MimeMessage mimeMessage) throws MessagingException {
  MimeMessageHelper messageHelper = new MimeMessageHelper(mimeMessage,
      true,
      Charsets.UTF_8.toString());
  try {
    messageHelper.setFrom(message.getFrom(), message.getFromName());
  } catch (UnsupportedEncodingException e) {
    throw new MessagingException(
        "UnsupportedEncodingException while encode 'the name of FROM person'",
        e);
  }
  messageHelper.setTo(message.getTo());

  if (message.getBcc() != null) {
    messageHelper.setBcc(message.getBcc());
  }

  if (message.getCc() != null) {
    messageHelper.setCc(message.getCc());
  }

  if (message.getReplyTo() != null) {
    messageHelper.setReplyTo(message.getReplyTo());
  }

  messageHelper.setSubject(message.getSubject());
  messageHelper.setText(message.getText());
}