Skip to content

Commit

Permalink
updated the email sender
Browse files Browse the repository at this point in the history
  • Loading branch information
Federico committed Jun 17, 2023
1 parent 5f4a526 commit 6578e66
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions intermediate_projects/email_sender/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,19 @@
from email.mime.image import MIMEImage
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from typing import Any
import credentials


def create_image_attachment(path: Any) -> MIMEImage:
def create_image_attachment(path: str) -> MIMEImage:
"""Create an image type for our email and add a header to it."""

try:
with open(path, 'rb') as image:
mime_image = MIMEImage(image.read())
mime_image.add_header('Content-Disposition', f'attachment; filename={path}')
return mime_image
except Exception as e:
print('Error:', e)
with open(path, 'rb') as image:
mime_image = MIMEImage(image.read())
mime_image.add_header('Content-Disposition', f'attachment; filename={path}')
return mime_image


def send_email(to_email: str, subject: str, body: str, image: Any = None):
def send_email(to_email: str, subject: str, body: str, image: str | None = None):
# Specify the host and the port
host: str = 'smtp-mail.outlook.com'
port: int = 587
Expand Down

0 comments on commit 6578e66

Please sign in to comment.