list - Python sending blank e-mails -
this question has reply here:
smtplib sends blank message if message contain characters 2 answersi have written code
import urllib.request import smtplib import re htmlweb = urllib.request.urlopen('url goes here') htmltext = htmlweb.read().decode('utf-8') regex = '<h2 itemprop="name">(.+?)</h2>' regex2 = '<div class="mediapagename">(.+?)</div>' pattern = re.compile(regex) pattern2 = re.compile(regex2) username = re.findall(pattern, htmltext) interests = re.findall(pattern2, htmltext) content = "the person's name is: " i=0 ii=0 while i<len(username): content += username[i] += 1 content += "\ntheir interests are: " while ii<len(interests): content += interests[ii] + ", " ii += 1 #----------------------------------------------- mail service = smtplib.smtp("smtp.gmail.com", 587) mail.ehlo() mail.starttls() mail.login('email here', 'password here') mail.sendmail('email here', 'here too', content) mail.close()
however, when run it, receive body-less e-mail. content variable prints out console, not e-mail body.
sorry if trivial; first time trying out python.
thank you!
the next question: smtplib sends blank message if message contain characters, points out must start content of message new line or else content part of message's header , not message's body.
i believe have change:
content = "the person's name is: "
to this:
content = "\nthe person's name is: "
python list email
No comments:
Post a Comment