-2

I am trying to send an email from my python project. But my method doesn't work with russian language.

import smtplib

server = smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()
server.login('mail@gmail.com', 'pasword')
server.sendmail('mail@gmail.com', 'another@gmail.com', 'привет')
server.quit()

I have this error: UnicodeEncodeError: 'ascii' codec can't encode character in position 0-4: ordinal not range(128) For English it is working. Python 3.6

Tomerikoo
  • 15,737
  • 15
  • 35
  • 52
  • 1
    Does this answer your question? [UnicodeEncodeError: 'ascii' codec can't encode character u'\xa0' in position 20: ordinal not in range(128)](https://stackoverflow.com/questions/9942594/unicodeencodeerror-ascii-codec-cant-encode-character-u-xa0-in-position-20) – Tomerikoo Feb 23 '21 at 16:31
  • This answer does spaces between letters: Н о в ы й к л и е н т И м я : S e r g e i S o k o v. Do you know how to remove these spaces? – Sergei Sokov Feb 23 '21 at 16:37

1 Answers1

4
server.sendmail('email.com', 'email.com', 'привет'.encode('utf-8'))
cigien
  • 55,661
  • 11
  • 60
  • 99
aetrnm
  • 11
  • 10