How can set name for source/from attribute on sent emails?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
The name shown in the From field of an email is the display name attached to the sender address. To set it correctly, you send a From header in the form Display Name <[email protected]> and make sure your mail provider allows that address and domain to send authenticated mail.
Understand the Two Parts of the From Header
The visible sender line normally contains:
- a display name, such as
Support Team - an email address, such as
[email protected]
In raw header form, that looks like this:
Most email APIs and SMTP libraries expose these as either one formatted string or separate name and email fields. The exact syntax depends on the tool, but the concept is the same.
The display name is presentation. The email address and domain are what authentication systems such as SPF, DKIM, and DMARC actually care about.
Set the Sender Name in Python
Python's standard library makes this straightforward:
formataddr() handles the proper header formatting, which is safer than building the string manually. If the display name contains spaces or non-ASCII characters, that helper is especially useful.
The recipient will usually see Support Team as the sender name, assuming the client does not replace it with a contact name from the user's address book.
Provider APIs Usually Have Explicit Name Fields
Many transactional email providers use structured JSON instead of raw headers. A typical payload looks like this:
Even though the API format changes, the result is still the same From header concept. If your provider supports separate source, from, or sender fields, read the documentation carefully because those fields can have different meanings.
From, Sender, and Reply-To Are Not the Same
A lot of confusion comes from mixing these headers:
- '
Fromis the visible author of the message' - '
Senderidentifies who actually sent the message on behalf of the author' - '
Reply-Tocontrols where replies go'
If you only want to change the visible name, set the From display name. Do not use Reply-To as a substitute. It changes reply behavior, not sender presentation.
This is common in support tools where the visible sender should be Billing Team, but replies should go to [email protected]. In that case, set both headers explicitly and intentionally.
Delivery Rules Still Apply
You cannot reliably send as any display name with any arbitrary address. Mail providers and receiving servers check whether the address and domain are authorized. If you send From: CEO <[email protected]> through a domain you do not control, the message may fail authentication, land in spam, or be rewritten by the provider.
The display name also is not guaranteed to appear exactly as sent. Some clients show the user's saved contact name instead. Others show only the email address on narrow screens. That is a client behavior issue, not a header-format bug.
Common Pitfalls
The biggest mistake is setting only the display name and forgetting that the address still must be valid and authenticated. A correct-looking From header does not override SPF, DKIM, or DMARC checks.
Another common issue is confusing From with Reply-To. If replies go to the wrong inbox, check which header you changed.
Do not manually concatenate complicated names without using your library's helper functions. Quoting and character encoding become error-prone quickly, especially with names that contain commas or non-English characters.
Finally, test in real clients. Gmail, Outlook, Apple Mail, and mobile clients do not always render the sender line in exactly the same way.
Summary
- The visible sender name comes from the display name in the
Fromheader. - Use the form
Display Name <[email protected]>or the equivalent structured API fields. - Keep
From,Sender, andReply-Toseparate in your design. - Make sure the sending address and domain are authenticated.
- Test the final rendering in the email clients your users actually use.

