0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Pythonによるメール配信(SMTPAuthenticationError )

Last updated at Posted at 2021-11-16

環境:Windows10 pro
python 3.9
VsCode

勉強の為に
pythonからコードを書いてメールをテスト送信しました。

from email import message
import smtplib

smtp_host = 'smtp.gmail.com'
smtp_port = 587
use_smtps = any
from_email ='#####@gmail.com'
to_email = '####@outlook.jp'
username = '####@gmail.com'
password = ''

msg = message.EmailMessage()
msg.set_content('Test email')
msg['Subject'] = 'Test email sub'
msg['From'] = from_email
msg['To'] = to_email

server = smtplib.SMTP(smtp_host, smtp_port)
server.ehlo()
server.starttls()
server.ehlo()
server.login(username, password)
server.send_message(msg)
server.quit()

パスワードはメールアカウントのパスワードと思い入力しました。
しかし、以下のエラーが発生。

例外が発生しました: SMTPAuthenticationError (534, b'5.7.9 Application-specific password required. Learn more at\n5.7.9  https://support.google.com/mail/?p=InvalidSecondFactor ot7sm2836890pjb.21 - gsmtp')

以下が参考になりました。
Pythonでメール(gmail)を送信できない場合の解決法

パスワードはgoogleはメールのパスワードではなくアプリパスワードを入力する。


password = 'googleアプリパスワード'

Gmailにメールが送信できました。


0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?