Giriş
Şu satırı dahil ederiz. Bu sınıf constructor içinde kendisine parametre olarak geçilen javax.mail.internet.MimeMessage nesnesini doldurmak için kolaylıklar sağlar.
import org.springframework.mail.javamail.MimeMessageHelper;
Kullanım
Örnek
Örnek
Şöyle yaparız
Örnek
MimeMessage message = javaMailSender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(message);
//Populate message with help of helper
javaMailSender.send(message);
constructor - MimeMessageÖrnek
Şöyle yaparız.
Şöyle yaparız.
MimeMessage message = javaMailSender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(message);
helper.setFrom(systemEmail);
helper.setTo(mailBacklog.getToAddress());
if(mailBacklog.getSubject() != null) {
helper.setSubject(mailBacklog.getSubject());
}
helper.setText(mailBacklog.getMessage());
javaMailSender.send(message);
setFrom metoduŞöyle yaparız.
MimeMessageHelper message = new MimeMessageHelper(mimeMessage);
String emailAddr = ...;
message.setTo(emailAddr);
message.setFrom("noreply@nomadlogicapp.com","noreply@nomadlogicapp.com");
message.setSubject("Test Email From Juju Console");
message.setText(str,true);
setText metodu
Birinci parametre text, ikinci parametre html metnidir.
Örnek
Şöyle yaparız
import org.springframework.mail.MailException;import org.springframework.mail.javamail.JavaMailSender;import org.springframework.mail.javamail.MimeMessageHelper;import org.springframework.mail.javamail.MimeMessagePreparator;import org.springframework.stereotype.Service;@Servicepublic class EmailService {private String emailFromAddress = ...;private String emailReplyToAddress = ...;@Autowiredprivate JavaMailSender emailSender;public void sendEmail(String recipient, String subject, EmailContentDto content)
throws MailException {MimeMessagePreparator messagePreparator = mimeMessage -> {MimeMessageHelper messageHelper = new MimeMessageHelper(mimeMessage, true);messageHelper.setFrom(emailFromAddress);messageHelper.setReplyTo(emailReplyToAddress);messageHelper.setTo(recipient);messageHelper.setSubject(subject);messageHelper.setText(content.getText(), content.getHtml());};emailSender.send(messagePreparator);}}
Hiç yorum yok:
Yorum Gönder