How to Set a Custom Sender Alias in Spring Boot Email

This guide explains why Spring Boot emails may show the default no‑reply address instead of a custom product name and demonstrates how to configure the sender alias using SimpleMailMessage or MimeMessage with code examples.

Programmer DD
Programmer DD
Programmer DD
How to Set a Custom Sender Alias in Spring Boot Email

In previous articles we covered the main scenarios for sending email with Spring Boot, such as basic sending, adding attachments, referencing static resources, and using templates.

When implementing the YouTube Chinese dubbing service, we discovered that recipients see the sender name as the email prefix (no‑reply) rather than the desired product alias (YouTube中文配音).

The MailProperties class does not provide a configuration option for an alias, so the alias must be set when constructing the mail message.

public class MailProperties {
    private static final Charset DEFAULT_CHARSET = StandardCharsets.UTF_8;
    private String host;
    private Integer port;
    private String username;
    private String password;
    private String protocol = "smtp";
    private Charset defaultEncoding = DEFAULT_CHARSET;
}

Example using SimpleMailMessage:

SimpleMailMessage message = new SimpleMailMessage();
message.setFrom("Programmer DD<[email protected]>"); // set sender alias
message.setTo("[email protected]");
message.setSubject("Subject: Simple Email");
message.setText("Test email content");
mailSender.send(message);

If you need to send more complex emails, you can use MimeMessage and set the alias in the same way with setFrom.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Backend DevelopmentSpring BootEmail AliasJava MailMailSender
Programmer DD
Written by

Programmer DD

A tinkering programmer and author of "Spring Cloud Microservices in Action"

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.