class Recipient
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.
/tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/outlook/mail/recipient.py
5 - 28
simple
Purpose
The Recipient class encapsulates user information for Office 365 Outlook operations, specifically wrapping an EmailAddress object to represent participants in email communications, calendar events, or group posts. It inherits from ClientValue, making it compatible with the Office 365 API client framework. The class provides convenient instantiation methods and ensures that every recipient has an associated email address.
Source Code
class Recipient(ClientValue):
"""Represents information about a user in the sending or receiving end of an event, message or group post."""
def __init__(self, email_address=None):
"""
:param EmailAddress email_address: The recipient's email address.
"""
if email_address is None:
email_address = EmailAddress()
super(Recipient, self).__init__()
self.emailAddress = email_address
def __repr__(self):
return repr(self.emailAddress)
@staticmethod
def from_email(value):
"""
:type value: str or EmailAddress
"""
if isinstance(value, EmailAddress):
return Recipient(value)
else:
return Recipient(EmailAddress(value))
Parameters
| Name | Type | Default | Kind |
|---|---|---|---|
bases |
ClientValue | - |
Parameter Details
email_address: An EmailAddress object representing the recipient's email address. If None is provided, a new empty EmailAddress object is automatically created. This parameter allows initialization with an existing EmailAddress instance or defaults to creating a new one.
Return Value
Instantiation returns a Recipient object with an emailAddress attribute. The from_email static method returns a new Recipient instance created from either a string email address or an EmailAddress object. The __repr__ method returns the string representation of the underlying EmailAddress object.
Class Interface
Methods
__init__(self, email_address=None)
Purpose: Initializes a new Recipient instance with an optional EmailAddress object
Parameters:
email_address: Optional EmailAddress object. If None, creates a new empty EmailAddress instance
Returns: None (constructor)
__repr__(self) -> str
Purpose: Returns the string representation of the Recipient by delegating to the EmailAddress object's repr
Returns: String representation of the underlying EmailAddress object
from_email(value) -> Recipient
static
Purpose: Static factory method to create a Recipient from either a string email address or an EmailAddress object
Parameters:
value: Either a string representing an email address or an EmailAddress object
Returns: A new Recipient instance wrapping the provided email information
Attributes
| Name | Type | Description | Scope |
|---|---|---|---|
emailAddress |
EmailAddress | The EmailAddress object containing the recipient's email information. Always initialized, either from the constructor parameter or as a new empty EmailAddress instance | instance |
Dependencies
office365
Required Imports
from office365.outlook.calendar.email_address import EmailAddress
from office365.runtime.client_value import ClientValue
Usage Example
from office365.outlook.calendar.email_address import EmailAddress
from office365.runtime.client_value import ClientValue
# Create a Recipient with a new EmailAddress
recipient1 = Recipient()
# Create a Recipient with an existing EmailAddress object
email_addr = EmailAddress('user@example.com')
recipient2 = Recipient(email_addr)
# Create a Recipient from a string email using the static factory method
recipient3 = Recipient.from_email('another@example.com')
# Create a Recipient from an EmailAddress object using the static factory method
email_obj = EmailAddress('third@example.com')
recipient4 = Recipient.from_email(email_obj)
# Access the email address
print(recipient3.emailAddress)
print(repr(recipient3))
Best Practices
- Use the from_email static method for convenient creation from string email addresses or EmailAddress objects
- The class automatically creates an empty EmailAddress if none is provided, ensuring the emailAddress attribute is always initialized
- This class is designed to work within the Office 365 API framework and inherits from ClientValue for proper serialization
- The __repr__ method delegates to the EmailAddress object, so string representation depends on EmailAddress implementation
- When creating multiple recipients, consider using the from_email factory method for cleaner code
- The class is immutable after construction - to change the email address, create a new Recipient instance
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
class EmailAddress 72.7% similar
-
class TranslationNotificationRecipient 68.8% similar
-
class AttendeeBase 62.3% similar
-
class TranslationNotificationRecipientCollection 60.3% similar
-
class EventReceiverDefinitionCreationInformation 60.0% similar