I am able to send emails with attachments such as images but unable to do so with csv files. I am pretty new to Python and unsure what to do next.
import os
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.application import MIMEApplication
import smtplib
email_address = os_environ.get(`EMAIL_ADDRESS`)
email_password = os.environ.get(`EMAIL_PASS`)
message = MIMEMultipart()
message['From'] = email_address
message['To'] = #Sending message to my email
message['Subject'] = `This is A Test Email`
message.attach(MIMEText('body'))
file_name = 'Daily_Ticket_Aging_Overview'
with open('C:/Users\\odigii01\\Desktop\\Daily_Ticket_Aging_Overview.csv', 'rb') as file:
message.attach(MIMEApplication(file.read(), Name = file_name))
with smtplib.SMTP(host='smtp.gmail.com', port=587) as smtp:
smtp.ehlo() #Telling the client that we want to send an email
smtp.starttls() #TLS MODE (Transport Layer Security)
smtp.login(email_address, email_password)
smtp.send_message(message)
print('Sent...')
Realized the data is being pulled but not as a CSV File. I can download the data and open it in the Notepad.