sending advanced .txt file with smtplib
Posted: Wed Nov 12, 2014 10:04 pm
hello,
I wrote a script to automatically send a .txt file to my e-mail address. This was working fine. But when I add an "•" to the text file, it throws me an error.
this is the error:
and this is my script:
does anybody know how to solve this?
I wrote a script to automatically send a .txt file to my e-mail address. This was working fine. But when I add an "•" to the text file, it throws me an error.
this is the error:
Code: Select all
UnicodeEncodeError: 'ascii' codec can't encode character '\u2022' in position 584: ordinal not in range(128)Code: Select all
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
import time
to = "****@***.com"
server= "*****"
port = "***"
user= "****@***.com"
pasw= "**********"
msg=MIMEMultipart()
msg["From"]=user
msg["To"]= to
msg["Subject"]="Daily logging file."
body="Date: %s\n\nYour daily log is attached."%(time.strftime("%m/%d/%Y"))
log = open("log.txt","r")
attachment= MIMEText(log.read())
attachment.add_header("Content-Disposition","attachment",filename="log.txt")
msg.attach(MIMEText(body,"plain"))
msg.attach(attachment)
smtpserver= smtplib.SMTP(server,port)
smtpserver.starttls()
smtpserver.login(user,pasw)
smtpserver.ehlo()
smtpserver.sendmail(user,to,msg.as_string())
smtpserver.quit()