-1
私は間違っていますか?とてもシンプルにする必要があります。実行後、何も起こりません。エラーもメールもありません。何もない。 私はJupyterを使用しています。Pythonを使用して電子メールを送信できません
def send_email(user, pwd, recipient, subject, body):
import smtplib
gmail_user = '[email protected]'
gmail_pwd = 'pass'
FROM = '[email protected]'
TO = '[email protected]'
SUBJECT = 'Test'
TEXT = 'Hello, this is test email'
# Prepare actual message
message = """From: %s\nTo: %s\nSubject: %s\n\n%s
""" % (FROM, ", ".join(TO), SUBJECT, TEXT)
try:
server = smtplib.SMTP("smtp.gmail.com", 587)
server.ehlo()
server.starttls()
server.login(gmail_user, gmail_pwd)
server.sendmail(FROM, TO, message)
server.close()
print ('successfully sent the mail')
except:
print ("failed to send mail")
'try/except'を取り除いて、例外メッセージ – Bahrom
を見ると、それは関数の定義のみです。この機能を実行しましたか?すなわち、 'send_email(" [email protected] "、" MyPaSwOrD "、" [email protected] "、" Money for you "、"こんにちは、お金があります ")' – furas
@furasありがとう。私はPythonの初心者です。私はあなたが言ったことをしました。 SMTPAuthenticationError:(535、b'5.7.8ユーザー名とパスワードは受け入れられません。\ n5.7.8 https://support.google.com/mail/?p=BadCredentials e26sm1483410pfi.10で詳細を確認してください。 - gsmtp ') '。しかしそれはもう一つの質問です。ご協力いただきありがとうございます。あなたの答えを投稿して、私はそれを受け入れるでしょう。 – Oleg