djblets.mail.utils¶
General utility functions for working with e-mail.
- build_email_address(email: str, full_name: Optional[str] = None) str [source]¶
Build an e-mail address for a To/CC/BCC field from a user’s information.
- build_email_address_for_user(user: User) str [source]¶
Build an e-mail address for a To/CC/BCC field from a User.
- Parameters:
user (
django.contrib.auth.models.User
) – The user.- Returns:
A formatted e-mail address intended for a To/CC/BCC field.
- Return type:
- build_email_address_via_service(email: str, full_name: Optional[str] = None, service_name: Optional[str] = None, sender_email: Optional[str] = None) str [source]¶
Build an e-mail address for sending on behalf of a user via a service.
This will construct a formatted e-mail address that can be safely used in a From field without risking being quarantined/rejected by DMARC rules.
The address will be in the form of “Full Name via Service Name <sender@domain.tld>”.
- Parameters:
email (
str
) – The unformatted e-mail address of the user.full_name (
str
, optional) –The full name of the user.
If not provided, the username in the e-mail address will be used.
service_name (
str
, optional) –The name of the service sending the e-mail.
If not provided,
settings.EMAIL_DEFAULT_SENDER_SERVICE_NAME
will be used.sender_email (
str
, optional) –The unformatted e-mail address for the sending service.
If not provided, the e-mail address in
DEFAULT_FROM_EMAIL
will be used.
- Returns:
A formatted e-mail address safe to use in a From field.
- Return type: