我能够使用python脚本发送邮件,这是我的代码
import smtplib, ssl
smtp_server = "xxx.yyyy.com"
sender_email = "[email protected]"
receiver_email = "[email protected]"
username ='DRAETWK'
password = 'password'
message = """\
Subject: Test Mail
This message is sent from Python."""
context = ssl.create_default_context()
with smtplib.SMTP(smtp_server) as server:
server.login(username, password)
server.sendmail(sender_email, receiver_email, message)
print('Mail Sent... Check your inbox')
邮件发送代码有效,但是当我使用相同的用户详细信息时,我无法阅读我的邮件,出现登录失败的问题,这是代码
import imaplib
import email.header
from smtplib import SMTP as SMTP
host = 'xxx.yyyy.com'
user = '[email protected]'
login_user= 'qweqwr'
password = 'xsw2zsadsadaaq1'
# Connect to the server
print('Connecting to ' + host)
mailBox = imaplib.IMAP4_SSL(host)
mailBox.debug = 100
print(mailBox)
# Login to our account
mailBox.login(login_user, password)
有人可以帮忙吗?
您需要使用从gmail生成的16位密码,我使用了您的方法,并且我使用了您的方法并且运行良好]]
Connecting to imap.gmail.com
<imaplib.IMAP4_SSL object at 0x00000000029A54A8>
03:41.68 > b'PDIK1 LOGIN @gmail.com "16 digit password"'
03:42.55 < b'* CAPABILITY IMAP4rev1 UNSELECT IDLE NAMESPACE QUOTA ID XLIST CHILDREN X-GM-EXT-1 UIDPLUS ENABLE MOVE CONDSTORE ESEARCH UTF8=ACCEPT LIST-EXTENDED LIST-STATUS LITERAL- SPECIAL-USE APPENDLIMIT=35651584'
03:42.55 matched r'b'\\* (?P<type>[A-Z-]+)( (?P<data>.*))?'' => (b'CAPABILITY', b' IMAP4rev1 UNSELECT IDLE NAMESPACE QUOTA ID XLIST CHILDREN X-GM-EXT-1 UIDPLUS ENABLE MOVE CONDSTORE ESEARCH UTF8=ACCEPT LIST-EXTENDED LIST-STATUS LITERAL- SPECIAL-USE APPENDLIMIT=35651584', b'IMAP4rev1 UNSELECT IDLE NAMESPACE QUOTA ID XLIST CHILDREN X-GM-EXT-1 UIDPLUS ENABLE MOVE CONDSTORE ESEARCH UTF8=ACCEPT LIST-EXTENDED LIST-STATUS LITERAL- SPECIAL-USE APPENDLIMIT=35651584')
03:42.55 untagged_responses[CAPABILITY] 0 += ["b'IMAP4rev1 UNSELECT IDLE NAMESPACE QUOTA ID XLIST CHILDREN X-GM-EXT-1 UIDPLUS ENABLE MOVE CONDSTORE ESEARCH UTF8=ACCEPT LIST-EXTENDED LIST-STATUS LITERAL- SPECIAL-USE APPENDLIMIT=35651584'"]
03:42.55 < b'PDIK1 OK [email protected] authenticated (Success)'
03:42.55 matched r'b'(?P<tag>PDIK\\d+) (?P<type>[A-Z]+) (?P<data>.*)'' => (b'PDIK1', b'OK', b'@gmail.com authenticated (Success)')