Skip to content
Advertisement

Error “email has no attribute encode” sending email in python

I am trying to send an email using MIME in python. Below is the code I am using :

JavaScript

but its giving me the below error:

module email has no attribute encode

at line:

s.sendmail("xyz@gmail.com", recipients, msg.as_bytes())

I am not able to understand why its giving this error. I have tried only using msg instead of msg.as_bytes() but its still the same. Can anyone please point out the issue in the code. Thanks

Advertisement

Answer

Looks like a typo to me.

You have assigned the module email when calling msg['To'] = email. That module must have been imported outside of the shared code (check your imports, it’s probably there!). msg.as_string() is simply having trouble parsing the module object (since modules don’t have the encode attribute).

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement