So im having trouble sending a textfile with my program in python
import smtplib, email, ssl
from email.mime.text import MIMEText
port = 465 #465 is the standard port of SMTP over SSL
smtp_server = "smtp.gmail.com"
sender_email = "xxx@gmail.com"
receiver_email = "xxx@gmail.com"
password = input("Enter your password: ")
filename = "C:\\Users\\nothi\\Desktop\\logs.txt"
message = """\
Subject: Hi there
Attached is the log file from the logging system."""
context = ssl.create_default_context()
with smtplib.SMTP_SSL(smtp_server, port, context=context) as server:
server.login(sender_email, password)
server.sendmail(sender_email, receiver_email, message, message.attach(MIMEText(open(filename).read())))
When i run the code it prompts me for my password which is file but after i get the following error:
Traceback (most recent call last):
File "C:/Users/nothi/Desktop/code/python/emailfiletest.py", line 19, in <module>
server.sendmail(sender_email, receiver_email, message, message.attach(MIMEText(open(filename).read())))
AttributeError: 'str' object has no attribute 'attach'