私はpythonを使用して電子メールを送信しようとしています。私はStackoverflowで多くのソリューションを試しましたが、うまくいきませんでした。pythonを使用してGmailサーバーを使用して電子メールを送信できません
私のコードがある -
import smtplib
fromaddr = '[email protected]'
toaddrs = '[email protected]'
msg = 'msg text here'
username = '[email protected]'
password = 'pwd'
server = smtplib.SMTP('smtp.gmail.com',587)
server.ehlo()
server.starttls()
server.ehlo()
server.login(username,password)
server.sendmail(fromaddr, toaddrs, msg)
server.quit()
コード行server = smtplib.SMTP('smtp.gmail.com',587)
しようとしたポート465で立ち往生し、このエラーを取得したまま -
Traceback (most recent call last):
File "gmail-python.py", line 130, in <module>
mainFunction()
File "gmail-python.py", line 101, in mainFunction
mail = smtplib.SMTP('smtp.gmail.com', 465)
File "/usr/lib/python2.7/smtplib.py", line 256, in __init__
(code, msg) = self.connect(host, port)
File "/usr/lib/python2.7/smtplib.py", line 317, in connect
(code, msg) = self.getreply()
File "/usr/lib/python2.7/smtplib.py", line 368, in getreply
raise SMTPServerDisconnected("Connection unexpectedly closed")
smtplib.SMTPServerDisconnected: Connection unexpectedly closed
はこの試みた - smtplib.SMTP_SSL('smtp.gmail.com',465)
をして、このエラーを得た
raise SMTPException("STARTTLS extension not supported by server.")
smtplib.SMTPException: STARTTLS extension not supported by server.
server.ehlo()を削除しても効果はありませんでした。エラーの下に発生し 削除server.starttlsは() -
raise SMTPAuthenticationError(code, resp)
smtplib.SMTPAuthenticationError: (534, '5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbsV\n5.7.14 3GHIcJvaksu56NrYm76aC0MqGI_sFI2cNaKSoFX6CV7TlyW593zn4dnJN7mG4TGI7edfcj\n5.7.14 l-MOV1Sb0Joyewnax8dxiL5BQ28Gg3UsWDfibI5TZ-tEaqqpL4WEzX5hsqYg6ZIQlczjyq\n5.7.14 UbElUx1C2E0QBt-X3uCuueb06uPBqehnwNV-hOlYFCgZpxRR9fdi-rO65oD5c1asYyGaTh\n5.7.14 1VRKgMYJp-o_uMhMjGEyJWKLLYX3A> Please log in via your web browser and\n5.7.14 then try again.\n5.7.14 Learn more at\n5.7.14 https://support.google.com/mail/answer/78754 r85sm13251579pfr.48 - gsmtp')
私はアカウントで安全性の低いアプリのアクセスを有効にしています。 ubuntuのPythonバージョン2.7.6。
フム用のGmailにアクセスしてから、サードパーティのアプリケーションを防止することができます。私はちょうどあなたの正確なコードを試して、Python 3.4.3/Win32上でうまく動作します。他のプラットフォームでもほぼ同じように試しました。あなたのエラーはあなたのアカウントの言及の前に起こるので、特定のGmailアカウントとは関係ありません。接続があることを確認するためにhttp://stackoverflow.com/questions/11545166/sending-email-in-python-did-google-change-something-regarding-gmail#comment15266517_11545166を試しましたか? (telnet smtp.gmail.com 587)どのようなpythonのバージョンを使用していますか? –
ubuntuのpythonバージョン2.7.6 – User42