I am attempting to write a script that scrapes some text off a website and then sends said text to me via email.
All of it is working as desired except for the encoding. The email contains lines such as this:
We say, ???Well, it???s all over and ruined now; what???s the
Obviously, the "???" should be apostrophes. I'm not terribly familiar with the intricacies of how encoding works especially when it pertains to email so any help would be appreciated. The pertinent part of my script is below:
msg = MIMEMultipart()
msg['From'] = fromaddr
msg['To'] = toaddrs
msg['Subject'] = "Daily Utmost Devo"
# webtext, cleanverse, & cleanlink are all <type 'unicode'> at this point
body = webtext.encode('utf-8')
bodyverse = cleanverse.encode('utf-8')
bodylink = cleanlink.encode('utf-8')
msg.attach(MIMEText(body, 'plain'))
msg.attach(MIMEText(bodyverse, 'plain'))
msg.attach(MIMEText(bodylink, 'plain'))
username = 'xxxxx@gmail.com'
password = 'xxxxx'
server = smtplib.SMTP('smtp.gmail.com:587')
server.ehlo()
server.starttls()
server.ehlo()
server.login(username, password)
text = msg.as_string()
server.sendmail(fromaddr, toaddrs, text)
server.quit()