Write emails functions
Function to send emails to participants
- class write_email.EmailHandler(email_username, email_domain='smtp.gmail.com', port=587, password=None, verbose=False)
A class to handle email operations including sending emails and reading email content from a file.
- read_content_from_textfile(textfile, sender_name, recipient_name)
Reads a text file and replaces placeholders with sender and recipient names.
- Parameters:
textfile (str) – The path to the text file.
sender_name (str) – The name of the sender.
recipient_name (str) – The name of the recipient.
- Returns:
The content of the text file with placeholders replaced.
- Return type:
str
- Raises:
FileNotFoundError – If the provided textfile path does not exist.
- write_email(email_address, subject, content, from_address=None)
Writes and sends an email.
- Parameters:
email_address (str) – The recipient email address.
subject (str) – The subject of the email.
content (str) – The content of the email.
from_address (str, optional) – The sender’s email address. If None, the initialized username is used. Defaults to None.
- Returns:
0 if the email is sent successfully.
- Return type:
int
- Raises:
SMTPRecipientsRefused – If recipient’s mail server did not accept the email.
SMTPHeloError – If the server didn’t reply properly to the HELO greeting.
SMTPSenderRefused – If the server didn’t accept the from_addr.
SMTPDataError – If the server replied with an unexpected error code.
- write_email.send_emails(df, email_username, email_smtp_domain, email_password=None, email_smtp_port=587, dry_run=False)
Function that sends emails to the participants of a ride share program based on groups created.
- Parameters:
df (pandas.DataFrame) – The DataFrame containing participant information, including names, email addresses, and groups. Required columns are [“Name”, “Email”, “arrival_group”, “departure_group”, “date_time_of_airport_arrival”, “date_time_of_hotel_departure”].
email_username (str) – The username of the email to be used to send emails.
email_smtp_domain (str) – The SMTP domain for the email to be used.
email_password (str, optional) – The password of the email to be used to send emails. If None, user will be prompted for password. Default is None.
email_smtp_port (int, optional) – The SMTP port to be used for the email server. Default is 587.
- Raises:
AssertionError – If ‘arrival_group’ and ‘departure_group’ columns are not found in the DataFrame.