import smtplib
server = smtplib.SMTP( "smtp.gmail.com", 587 )
server.starttls()
server.login( 'myEmail@gmail.com', 'myPassword' )
file = 'C:\\Users\\PC1\\Desktop\\myFile.txt'
f = open(file, "r")
filecontent = (f.read())
server.sendmail( 'example@gmail.com', 'example@gmail.com', filecontent )
When I run this code, i get an error like this;
Traceback (most recent call last):
File "C:\Users\PC1\Desktop\pyos\mail.py", line 10, in <module>
server.sendmail( 'example@gmail.com', 'example@gmail.com', filecontent )
File "C:\Users\PC1\AppData\Local\Programs\Python\Python36-32\lib\smtplib.py", line 854, in sendmail
msg = _fix_eols(msg).encode('ascii')
UnicodeEncodeError: 'ascii' codec can't encode character '\u0131' in position 31: ordinal not in range(128)
How can I overcome this? I don't want a character problem in the file I send.