Python Forum
ASCII-Codec in Python3 [SOLVED]
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ASCII-Codec in Python3 [SOLVED]
#3
(Jul-07-2021, 06:39 PM)Gribouillis Wrote: The documentation of smtplib.SMTP.sendmail() says
Quote:msg may be a string containing characters in the ASCII range, or a byte
string. A string is encoded to bytes using the ascii codec, and lone
\r and \n characters are converted to \r\n characters.
As you want to send a string containing characters outside the ASCII range, I suggest that you encode the string manually using another encoding, such as utf8, so try this
msg = (headers + "\r\n\r\n" + content).encode('utf8')
session.sendmail(GMAIL_USERNAME, recipient, msg)

Thanks for your reply.
I edited the ending of my file to this (I hope you meant that).

        #Send Email & Exit
        msg = (headers + "\r\n\r\n" + content).encode('utf8')
        session.sendmail(GMAIL_USERNAME, recipient, msg)
        session.quit

sender = Emailer()

sendTo = receiver
emailSubject = "Subject"
emailContent = "ÄÖÜ"

#Sends an email to the "sendTo" address with the specified "emailSubject" as the subject and "emailConten$
sender.sendmail(sendTo, emailSubject, emailContent)
When I try to execute it I get the following error:

  File "debug2.py", line 40
    msg = (headers + "\r\n\r\n" + content).encode('utf8')
                                                        ^
TabError: inconsistent use of tabs and spaces in indentation
I don't see the error here tbh.
Reply


Messages In This Thread
ASCII-Codec in Python3 [SOLVED] - by AlphaInc - Jul-07-2021, 06:15 PM
RE: ASCII-Codec in Python3 - by Gribouillis - Jul-07-2021, 06:39 PM
RE: ASCII-Codec in Python3 - by AlphaInc - Jul-07-2021, 06:55 PM
RE: ASCII-Codec in Python3 - by Gribouillis - Jul-07-2021, 07:03 PM
RE: ASCII-Codec in Python3 - by AlphaInc - Jul-07-2021, 07:05 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Question UnicodeEncodeError: 'ascii' codec can't encode character u'\xe8' in position 562: ord ctrldan 23 4,962 Apr-24-2023, 03:40 PM
Last Post: ctrldan
  [SOLVED] [Debian] UnicodeEncodeError: 'ascii' codec Winfried 1 1,042 Nov-16-2022, 11:41 AM
Last Post: Winfried
  UnicodeEncodeError: 'ascii' codec can't encode character '\xfd' in position 14: ordin Armandito 6 2,789 Apr-29-2022, 12:36 PM
Last Post: Armandito
  codec for byte transparency Skaperen 7 3,877 Sep-25-2020, 02:20 AM
Last Post: Skaperen
  'charmap' codec louis216 4 20,260 Jun-30-2020, 06:25 AM
Last Post: louis216
  Which codec can help me decode the html source? vivekagrey 4 3,233 Jan-10-2020, 09:33 AM
Last Post: DeaD_EyE
  Gnuradio python3 is not compatible python3 xmlrpc library How Can I Fix İt ? muratoznnnn 3 4,957 Nov-07-2019, 05:47 PM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020