0

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"] = "abcd@gmail.com"
msg["To"] = "abcdefg@gmail.com"

smtp = smtplib.SMTP("smtp.gmail.com", 587)
smtp.ehlo()
smtp.starttls()
smtp.ehlo()

smtp.login("abcd@gmail.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?

  • 1
    Your question is unclear - it seems to have lots of irrelevant inclusions, while missing important code. If reading the Python documentation doesn't help you may find someone who has used these modules. I normally use ssmpt on the Pi which can send any of the normal email coding methods (UTF-8, Base64) – Milliways May 11 at 6:09
1

You need to run your program with python3 not python.

  • The question claimed it worked on a MacBook - which doesn’t have python3. It would require additional installation and explicit call to run. – Milliways May 12 at 7:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.