Reputation: 97
I am making a script which checks a website for auctions interested for me. If it finds an interested link, it adds this link to listalink
with listalink.append(link)
. When I am sending an email I have this error:
AttributeError: 'list' object has no attribute 'encode'.
import smtplib
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText
# listalink example:
listalink = ["http://www.google.pl", "http://www.facebook.com", "http://amazon.com"]
def email_sender():
fromaddr = "[email protected]"
toaddr = "[email protected]"
msg = MIMEMultipart()
msg['From'] = fromaddr
msg['To'] = toaddr
msg['Subject'] = "NEW INTERESTED AUCTIONS"
body = listalink
msg.attach(MIMEText(body, 'plain'))
server_ssl = smtplib.SMTP_SSL("smtp.wp.pl", 465)
server_ssl.ehlo()
server_ssl.login("[email protected]", "password")
text = msg.as_string()
server_ssl.sendmail(fromaddr, toaddr, text)
server_ssl.close()
print 'E-mail sent'
Upvotes: 0
Views: 3336
Reputation: 903
the error occurs because you add list
to email's body (the body must be str
):
body = listalink
Solution:
listalink = ["http://www.google.pl", "http://www.facebook.com", "http://amazon.com"]
listalink = " ".join(listalink)
Upvotes: 3