smtplib (python 3.6) で複数の電子メールを送信すると「中止 (切断)」され、オンラインで多くの情報を見つけることができません。エラーは私のコードではなくサーバーからのものであると確信していますが、これを修正する方法を知りたいか、少なくとも何をグーグルで検索して詳細情報を取得するかの手がかりを得たいと思います。これを修正します。
これは、1通の電子メールを送信するために使用している関数です:(この関数を5回呼び出して、エラーが発生しています)。
import smtplib
def enviar_um_mail(to, subject, body):
#source: https://stackabuse.com/how-to-send-emails-with-gmail-using-python/
user = '<mail here>'
password = '<passwrd here>'
sent_from = user
to = 'somemail@somedomain.org'
email_text = 'text of e-mail here'
try:
server = smtplib.SMTP_SSL('smtp.gmail.com', 465)
server.ehlo()
server.login(user, password)
server.sendmail(sent_from, to, email_text)
server.close()
print ('Email sent!')
except Exception as e:
print ('Something went wrong...')
print(e)
この関数を 5 回呼び出すと、Python シェルは次のように表示します。
Email sent!
Email sent!
Email sent!
Email sent!
Email sent!aborted (disconnected)