-2

I have this remote keylogger and it works fine at first to send the emails but after a few minutes it stops sending emails and it throws me this error:

Exception in thread Thread-25:
Traceback (most recent call last):
  File "C:\Users\Lisandro0\AppData\Local\Programs\Python\Python37\lib\threading.py", line 926, in _bootstrap_inner
    self.run()
  File "C:\Users\Lisandro0\AppData\Local\Programs\Python\Python37\lib\threading.py", line 1177, in run
    self.function(*self.args, **self.kwargs)
  File "C:\Users\Lisandro0\Desktop\Desktop3\keylogger\crack.py", line 64, in report
    self.sendmail(EMAIL_ADDRESS, EMAIL_PASSWORD, self.log)
  File "C:\Users\Lisandro0\Desktop\Desktop3\Keylogger\crack.py", line 53, in sendmail
    server.sendmail(email, email, message)
  File "C:\Users\Lisandro0\AppData\Local\Programs\Python\Python37\lib\smtplib.py", line 855, in sendmail
    msg = _fix_eols(msg).encode('ascii')
UnicodeEncodeError: 'ascii' codec can't encode character '\xf1' in position 312: ordinal not in range(128)

I would appreciate reading the code as it is short.

I appreciate any help

Sergey Shubin
  • 3,040
  • 4
  • 24
  • 36
Tomy ruby
  • 1
  • 2

1 Answers1

0

The error message is clear:

...Python37\lib\smtplib.py...UnicodeEncodeError: 'ascii' codec can't encode character '\xf1' in position 312: ordinal not in range(128)

It seems that smtplib has problem encoding your mail content.

I did some source code reading. In smtplib.py:

    def sendmail(self, from_addr, to_addrs, msg, mail_options=(),
                 rcpt_options=()):
        """This command performs an entire mail transaction.

        The arguments are:
            - from_addr    : The address sending this mail.
            - to_addrs     : A list of addresses to send this mail to.  A bare
                             string will be treated as a list with 1 address.
            - msg          : The message to send.
            - mail_options : List of ESMTP options (such as 8bitmime) for the
                             mail command.
            - rcpt_options : List of ESMTP options (such as DSN commands) for
                             all the rcpt commands.

        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.

Look here:

msg may be a string containing characters in the ASCII range, or a byte string

If you want to send mail of non-ascii content, you can encode the content into a byte string first.

(By the way, if I got it right, your question title is somewhat off the point, failing to grasp the key of your problem.)

fishoverflow
  • 91
  • 1
  • 5
  • Could you explain or give me an idea of how to insert that code in my source code, I've only been learning python for a few days, I only know html, css and php, but if you could help me I would appreciate it very much. By: thanks for the previous answer I already understood the problem but I still don't know how to solve it – Tomy ruby Sep 18 '20 at 03:08
  • In your function `sendmail`, there is a line of code which calls smtplib's sendmail method: `server.sendmail(email, email, message)` As the doc string said, `sendmail` can accept a byte-string or a string. To pass it a byte-string rather than a string which will error when `message` is non-ascii, you need to convert `message` to byte-string type. Maybe you can try adding some type-converting stuff like `message = message.encode('utf8')` before calling `server.sendmail`. – fishoverflow Sep 18 '20 at 03:47
  • Note you can mess around in a session to explore these things: ```python >>> s = '中文' >>> t = s.encode('utf8') >>> type(s) >>> type(t) >>> ``` You can also do some searching regarding to string and byte-string in python. – fishoverflow Sep 18 '20 at 03:47