🔍 Code Extractor

class EmailAddress

Maturity: 45

A data class representing an email address with an associated display name, inheriting from ClientValue for use in Office 365 API operations.

File:
/tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/outlook/calendar/email_address.py
Lines:
4 - 20
Complexity:
simple

Purpose

This class encapsulates email contact information, storing both the email address and display name of a person or entity. It is designed to work within the Office 365 SDK as a client-side value object for representing email recipients or contacts. The class provides string representations for both simple address display and formatted name-address combinations.

Source Code

class EmailAddress(ClientValue):
    """The name and email address of a contact or message recipient."""

    def __init__(self, address=None, name=None):
        """
        :param str address: The email address of the person or entity.
        :param str name: The display name of the person or entity.
        """
        super(EmailAddress, self).__init__()
        self.address = address
        self.name = name

    def __str__(self):
        return self.address

    def __repr__(self):
        return "{0} <{1}>".format(self.name, self.address)

Parameters

Name Type Default Kind
bases ClientValue -

Parameter Details

address: The email address string of the person or entity (e.g., 'user@example.com'). Optional parameter that defaults to None if not provided during instantiation.

name: The display name string of the person or entity (e.g., 'John Doe'). Optional parameter that defaults to None if not provided during instantiation.

Return Value

Instantiation returns an EmailAddress object with address and name attributes set to the provided values or None. The __str__ method returns the email address string, while __repr__ returns a formatted string in the format 'Name <address@example.com>'.

Class Interface

Methods

__init__(self, address=None, name=None)

Purpose: Constructor that initializes an EmailAddress instance with optional address and name parameters

Parameters:

  • address: Optional string representing the email address (e.g., 'user@example.com'). Defaults to None.
  • name: Optional string representing the display name (e.g., 'John Doe'). Defaults to None.

Returns: None (constructor)

__str__(self) -> str

Purpose: Returns the string representation of the email address, providing just the address portion

Returns: The email address string (value of self.address attribute)

__repr__(self) -> str

Purpose: Returns a formatted string representation combining the name and address in standard email format

Returns: A formatted string in the format 'Name <address>' (e.g., 'John Doe <john.doe@example.com>')

Attributes

Name Type Description Scope
address str or None The email address string of the person or entity. Can be None if not set during initialization. instance
name str or None The display name string of the person or entity. Can be None if not set during initialization. instance

Dependencies

  • office365

Required Imports

from office365.runtime.client_value import ClientValue

Usage Example

from office365.runtime.client_value import ClientValue

class EmailAddress(ClientValue):
    def __init__(self, address=None, name=None):
        super(EmailAddress, self).__init__()
        self.address = address
        self.name = name
    
    def __str__(self):
        return self.address
    
    def __repr__(self):
        return "{0} <{1}>".format(self.name, self.address)

# Create an email address with both name and address
email = EmailAddress(address='john.doe@example.com', name='John Doe')

# Access the address
print(str(email))  # Output: john.doe@example.com

# Get formatted representation
print(repr(email))  # Output: John Doe <john.doe@example.com>

# Create with only address
email2 = EmailAddress(address='jane@example.com')
print(email2.address)  # Output: jane@example.com

# Create empty and set later
email3 = EmailAddress()
email3.address = 'admin@example.com'
email3.name = 'Administrator'

Best Practices

  • Always provide at least the address parameter when creating an EmailAddress instance for meaningful use, as the name is optional but the address is typically required for email operations.
  • Use str(email_obj) when you need just the email address string, and repr(email_obj) when you need a formatted display with both name and address.
  • This class is immutable by convention - set address and name during initialization or immediately after, rather than modifying them frequently during the object's lifecycle.
  • The class inherits from ClientValue, which is part of the Office 365 SDK, so it's designed to be serialized and used in API requests to Office 365 services.
  • Both address and name can be None, so always check for None values before using them in string operations if not set during initialization.
  • When using in Office 365 API contexts, this object will be automatically serialized to the appropriate format by the parent ClientValue class.

Similar Components

AI-powered semantic similarity - components with related functionality:

  • class Recipient 72.7% similar

    A class representing information about a user in the sending or receiving end of an event, message or group post in Microsoft Office 365 Outlook.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/outlook/mail/recipient.py
  • class PhysicalAddress 70.6% similar

    A data class representing the physical address of a contact with fields for city, country/region, postal code, state, and street.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/outlook/mail/physical_address.py
  • class EmailIdentity 64.9% similar

    A class representing the email identity of a user, extending the base Identity class with email-specific attributes.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/directory/permissions/email_identity.py
  • class SecondaryAdministratorsInfo 61.6% similar

    A data class representing secondary administrator information in an Office 365 context, storing email, login name, and user principal name.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/tenant/administration/secondary_administrators_info.py
  • class TranslationNotificationRecipient 60.7% similar

    A data class representing a recipient for translation notifications in Office 365, storing the login name of the user who should receive notifications.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/translation/notification_recipient.py
← Back to Browse