djblets.mail.utils¶
General utility functions for working with e-mail.
- build_email_address(email, full_name=None)¶
Build an e-mail address for a To/CC/BCC field from a user’s information.
- build_email_address_for_user(user)¶
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, full_name=None, service_name=None, sender_email=None)¶
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 (
unicode
) – The unformatted e-mail address of the user.full_name (
unicode
, optional) – The full name of the user. If not provided, the username in the e-mail address will be used.service_name (
unicode
, optional) – The name of the service sending the e-mail. If not provided,settings.EMAIL_DEFAULT_SENDER_SERVICE_NAME
will be used.sender_email (
unicode
, optional) – The unformatted e-mail address for the sending service. If not provided, the e-mail address inDEFAULT_FROM_EMAIL
will be used.
- Returns:
A formatted e-mail address safe to use in a From field.
- Return type: