我使用python從gmail發送電子郵件。我把gmail IMAP上也獲得一個安全密碼(一個16位密碼)。但回覆我的用戶名和密碼不被接受。谷歌帳戶密碼,端口25,587,465(使用SSL)。無法正常工作。蟒蛇smtp發送電子郵件從gmail,
#! /usr/bin/python
# -*- coding: UTF-8 -*-
from email.mime.text import MIMEText
from email.header import Header
from email import encoders
import smtplib
sender = "[email protected]"
rec= "[email protected]"
passwd = "security password"
#passwd = 'the really google account password'
message = MIMEText("郵件發送","plain","utf-8")
message['From'] =sender
message['To'] = rec
message['Subject'] =Header("from google","utf-8").encode()
smtpObj = smtplib.SMTP("smtp.gmail.com",587)
smtpObj.ehlo()
smtpObj.starttls()
smtpObj.set_debuglevel(1)
smtpObj.login(sender,passwd)
smtpObj.sendmail(sender,[rec],message.as_string)
smtpObj.close
其密碼我應該使用,谷歌帳戶密碼或安全密碼很適合我? –
此代碼不會嘗試使用除gmail密碼以外的任何密碼 –
另請參閱https://stackoverflow.com/questions/17332384/python-3-send-email-smtp-gmail-error-smtpexception/46754666#46754666 – axd