аватар question@mail.ru · 01.01.1970 03:00

Sending email. The letter is not sent with Cyrillic

Purpose: you need to send a letter to the mail. The letter has Cyrillic symbols.

The problem: the script works with Latin symbols, but does not work with the Cyrillic alphabet

script:

   Import  smtplibtext =  \   to =  'xxxxxx@gmail.com'  subject =  'xxxx'   # gmail sign in  gmail_sender =  'xxxx@gmail.com'  gmail_passwd =  'xxxxxx'  server = sMTPLIB.smtp ( '' "smtp.gmail.com ',  587 ) server.ehlo () server.starttls () server.login (gmail_sender, gmail_passwd) body =  '\ r \ n'  .join ([ 'to: % S'  class = ""> '' , text])   try :  server.sendmail (gmail_sender, body)   print )   except :   print  (' 'Error Sending Mail ') server.quit ()     

error:

  Traceback (Most Recent Call Last): : ) File  "" C: /users/babai/pycharmprojects/mail.py "" , line  47 ,  in  & lt; module & gt;  server.sendmail (gmail_sender, [to], body)  file , line  854 ,  'ascii' ) unicodeencodeerror:  'ascii'  codec Can  '' '' t enterode Characters in Position 63-74: Ordinal Not in Range (128)      

as I understand the problem of encoding. That is, the SMTPLIB module works only with ANSII ??

аватар answer@mail.ru · 01.01.1970 03:00

The problem is solved with the help of Mimetext

The solution is found here

thanks

  #-*-CODING: UTF-8 -* -     import  smtplib  from   Email.mime.text  Import  mimetext  from  email.header  import  headersmtp_host =  'SMTP.gmail.com'  # yahoo  login =  ""> ""> ""> ""> ""> ""> ""> ""> ""> ">" ">" ">" ">" ">"> "" " class = ""> "" xxxxxxx ""  recipients_emails =  "" xxxxxx@gmail.com ""  msg = mimetext ( '"thank you' ,  'Plain' ,  'utf-8' ) msg [ 'subject' ] = header ( 'Subject & Hellip;' ,  'utf-8' ) msg [ 'from "] = loginmsg [ 'to' ] = recipients_emailss = smtplib.smtp (smtp_host,  587 , timeout =  10 ) s.set_debuglevel ( 1 )   try :  s.starttls ()  s.login (login, password)   S.Sendmail (msg [ 'from' ], recipients_emails, msg.as_string ())   finally :   Print  (MSG)  S.QUit ()                                       

Latest

Similar