SMPT UnicodeEncodeError

  python

every time i run this code i get this : Traceback (most recent call last):

File "C:/Users/acer/Desktop/projects/email/main.py", line 19, in
connection.sendmail(from_addr=email, to_addrs="s*@yahoo.com", msg=f"Hello nn {quote}")
File "C:UsersacerDesktopPython 3.8libsmtplib.py", line 859, in sendmail
msg = _fix_eols(msg).encode(‘ascii’)
UnicodeEncodeError: ‘ascii’codec can’t encode character ‘u201c’ in position 11: ordinal not in
range(128)
import smtplib
import random
import datetime as dt

email = "s******@gmail.com"
passwrd = "******"


now = dt.datetime.now()
day = now.weekday()

if day == 3:
    with open("quotes.txt", encoding="utf8") as quote_file:
        quote = random.choice(quote_file.readlines())

    with smtplib.SMTP("smtp.gmail.com") as connection:
        connection.starttls()
        connection.login(email, passwrd)
        connection.sendmail(from_addr=email, to_addrs="sh***@yahoo.com", msg=f"Hello nn {quote}")

Source: Python Questions

One Reply to “SMPT UnicodeEncodeError”

LEAVE A COMMENT