I am trying to send a mail using Spring Boot. I am able to send the mail successfully but in the mailbox, I am seeing the alias name along with the from email address like Customer Desk[[email protected]]. I only want the from address alias name to be displayed in the mailbox like CustomerDesk. Below is my implementation of the same.
public class MailHandlerImpl implements MailHandler {
@Autowired
private JavaMailSender javaMailSender;
public void sendEmail() {
String emailToAddress = "[email protected]"
String emailFromAddress = "Customer Desk <[email protected]>"
MimeMessage mimeMessage = javaMailSender.createMimeMessage();
try {
MimeMessageHelper messageHelper = new MimeMessageHelper(mimeMessage, true);
mimeMessage.setFrom(new InternetAddress(emailFromAddress));
messageHelper.setTo(InternetAddress.parse(emailToAddress));
javaMailSender.send(mimeMessage);
} catch (MessagingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
Can anyone explain how I can only display the Alias name in the mailbox?
I am not too familiar with JavaMailSender. However, I think passing alias name like following should do the trick,
mimeMessage.setFrom(new InternetAddress("[email protected]", "Customer Desk"));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With