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.
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.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Programmer DD
A tinkering programmer and author of "Spring Cloud Microservices in Action"
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
