When I run this code:
import datetime import smtplib import re import email from email.mime.text import MIMEText import email.message from robobrowser import RoboBrowser from bs4 import BeautifulSoup contents = "This is some sample content." msg = MIMEText(contents) msg["Subject"] = "Today's Homework" msg["From"] = "email@example.com" msg["To"] = "firstname.lastname@example.org" smtp = smtplib.SMTP("smtp.gmail.com", 587) smtp.ehlo() smtp.starttls() smtp.ehlo() smtp.login("email@example.com", "password123") smtp.send_message(msg) smtp.close()
I get the following error:
Traceback (most recent call last): File "Program.py", line 54, in <module> smtp.send_message(msg) AttributeError: SMTP instance has no attribute 'send_message'
This error only occurs when I run this on my raspberry pi. This file runs without any issue on my macbook.
This is a code snippet of my program that is returning an error. Please note that the email and passwords have been changed for the purpose of posting this snippet online.
I would use the sendemail method instead but my the content has some non ascii characters which then return an error.
Can someone please tell me how to fix the error?