I want to send a trial email from Google, but I couldn't solve this error. There's something wrong with "mail.sendmail(messsage["From"], message["To"], message.as_string())
" right there. However, none of the methods I tried worked.
I looked at a few examples of this, but because the samples were a little different, I opened a new topic.
I will be grateful to you for your help
class SendMail:
def __init__(self, email, auth):
self.email = email
self.auth = auth
self.send()
def send(self):
try:
mail = smtplib.SMTP("smtp.gmail.com", 587)
mail.ehlo()
mail.starttls()
mail.login("example@gmail.com", "password")
message = MIMEMultipart()
message["Form"] = self.email
message["Subject"] = "Example Subject"
body = f"Test message : {self.auth}"
body_text = MIMEText(body, "plain")
message.attach(body_text)
mail.sendmail(messsage["From"], message["To"], message.as_string())
print("message was sent successfully..")
mail.close()
except Exception as e:
print(e)
Exactly the error message : 'NoneType' object has no attribute 'strip'