BAEL-4176: Set noreply@baeldung.com as the from address (#9536)
This commit is contained in:
parent
e2987ffae9
commit
eeaf6c9350
|
@ -30,11 +30,13 @@ import freemarker.template.TemplateException;
|
||||||
@Service("EmailService")
|
@Service("EmailService")
|
||||||
public class EmailServiceImpl implements EmailService {
|
public class EmailServiceImpl implements EmailService {
|
||||||
|
|
||||||
@Autowired
|
private static final String NOREPLY_ADDRESS = "noreply@baeldung.com";
|
||||||
public JavaMailSender emailSender;
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public SimpleMailMessage template;
|
private JavaMailSender emailSender;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private SimpleMailMessage template;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private SpringTemplateEngine thymeleafTemplateEngine;
|
private SpringTemplateEngine thymeleafTemplateEngine;
|
||||||
|
@ -43,11 +45,12 @@ public class EmailServiceImpl implements EmailService {
|
||||||
private FreeMarkerConfigurer freemarkerConfigurer;
|
private FreeMarkerConfigurer freemarkerConfigurer;
|
||||||
|
|
||||||
@Value("classpath:/mail-logo.png")
|
@Value("classpath:/mail-logo.png")
|
||||||
Resource resourceFile;
|
private Resource resourceFile;
|
||||||
|
|
||||||
public void sendSimpleMessage(String to, String subject, String text) {
|
public void sendSimpleMessage(String to, String subject, String text) {
|
||||||
try {
|
try {
|
||||||
SimpleMailMessage message = new SimpleMailMessage();
|
SimpleMailMessage message = new SimpleMailMessage();
|
||||||
|
message.setFrom(NOREPLY_ADDRESS);
|
||||||
message.setTo(to);
|
message.setTo(to);
|
||||||
message.setSubject(subject);
|
message.setSubject(subject);
|
||||||
message.setText(text);
|
message.setText(text);
|
||||||
|
@ -76,6 +79,7 @@ public class EmailServiceImpl implements EmailService {
|
||||||
// pass 'true' to the constructor to create a multipart message
|
// pass 'true' to the constructor to create a multipart message
|
||||||
MimeMessageHelper helper = new MimeMessageHelper(message, true);
|
MimeMessageHelper helper = new MimeMessageHelper(message, true);
|
||||||
|
|
||||||
|
helper.setFrom(NOREPLY_ADDRESS);
|
||||||
helper.setTo(to);
|
helper.setTo(to);
|
||||||
helper.setSubject(subject);
|
helper.setSubject(subject);
|
||||||
helper.setText(text);
|
helper.setText(text);
|
||||||
|
@ -118,12 +122,12 @@ public class EmailServiceImpl implements EmailService {
|
||||||
|
|
||||||
MimeMessage message = emailSender.createMimeMessage();
|
MimeMessage message = emailSender.createMimeMessage();
|
||||||
MimeMessageHelper helper = new MimeMessageHelper(message, true, "UTF-8");
|
MimeMessageHelper helper = new MimeMessageHelper(message, true, "UTF-8");
|
||||||
|
helper.setFrom(NOREPLY_ADDRESS);
|
||||||
helper.setTo(to);
|
helper.setTo(to);
|
||||||
helper.setSubject(subject);
|
helper.setSubject(subject);
|
||||||
helper.setText(htmlBody, true);
|
helper.setText(htmlBody, true);
|
||||||
helper.addInline("attachment.png", resourceFile);
|
helper.addInline("attachment.png", resourceFile);
|
||||||
emailSender.send(message);
|
emailSender.send(message);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue