When I try to send an email via Gmail using smtp.log on Python 3, they say AttributeError: module 'smtplib' has no attribute 'SMTP'.Please tell me what's wrong.
batchMailerOne.py
#!/usr/bin/env python3
#
# # batchMailerOne.py
# -*-coding:utf-8-*-
#### START CUSTOMIZATION ####
smtp_host='smtp.gmail.com'
smtp_port = 587
from_email='foo<[email protected]>'
mail_subject='bar'
user_name='xxxxx no suchmail [email protected]'#Gmail login name
user_password='xxxxxxxx'#Gmail pssswd (2 steps authorization is not supported)
# set mail address surrounded in double quote, ended with comma (you can send up to 100 mails a day)
to_emails=[
"recipient1<[email protected]>",
"recipient2<[email protected]>",
"recipient3<[email protected]>",
]
# write your message between ' ' ' ' and ' ' '
message_text = ''
Dear someone,
Hello
'''
### END CUSTOMIZATION###
from email import message
import smtplib
server=smtplib.SMTP(smtp_host, smtp_port)
server.ehlo()
server.starttls()
server.ehlo()
server.login(user_name, user_password)
for to_email in to_emails:
msg = message.EmailMessage()
msg.set_content(message_text)
msg ['Subject'] = mail_subject
msg ['From'] = from_email
msg ['To'] = to_email
server.send_message(msg)
server.quit()
Runtime Error
Traceback (most recent call last):
File "C:\Users\cf\batchMailerOne.py", line 31, in <module>
import smtplib
File "C:\Users\cf\Anaconda3\lib\smtplib.py", line 49, in<module>
import email.generator
File "C:\Users\cf\Anaconda3\lib\email\generator.py", line 14, in<module>
from copy import deepcopy
File "C:\Users\cf\Anaconda3\lib\copy.py", line 60, in<module>
from org.python.core import PyStringMap
File "C:\Users\cf\batchMailerOne.py", line 39, in <module>
server=smtplib.SMTP(smtp_host, smtp_port)
AttributeError: module 'smtplib' has no attribute 'SMTP'
Python version
C:\Users\cf>\Users\cf\Anaconda3\python.exe-V
Python 3.6.3:: Anaconda, Inc.
Do you happen to have a file called org.pyc
compiled by bytes in the batchMailer\Resources
folder?
-- This is to post comment from metropolis as a community wiki response
In my (non-anaconda, original) environment, an error occurred much earlier.
Imagine that there is a problem with the environment created in Anaconda.
smtplib.SMTPAUTHENTICATIONError: (535, b'5.7.8 Username and Password not accepted.Learn more at
5.7.8 https://support.google.com/mail/?p= BadCredentials t4-v6sm41336798 pfh.45-gsmtp')
578 Understanding How to Configure Google API Key
581 PHP ssh2_scp_send fails to send files as intended
572 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
914 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
574 Who developed the "avformat-59.dll" that comes with FFmpeg?
© 2024 OneMinuteCode. All rights reserved.