Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Boot - Set Alias name for email address

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?

like image 202
Jestino Sam Avatar asked Nov 20 '25 10:11

Jestino Sam


1 Answers

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"));
like image 112
Runcorn Avatar answered Nov 22 '25 01:11

Runcorn



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!