[英]How to send email with smtplib in Python with outlook account
I was following this post to send an email using my outlook account: Having trouble with sending an email through SMTP Python 我正在关注此帖子以使用我的Outlook帐户发送电子邮件:通过SMTP Python发送电子邮件时遇到问题
I used that and made a simple test code as follows 我使用了它,并做了一个简单的测试代码,如下所示
username='****'
password='***'
mailServer = smtplib.SMTP('smtp-mail.outlook.com', 587)
mailServer.ehlo()
mailServer.starttls()
mailServer.ehlo()
mailServer.login(username, password)
But it fails with this error 但是由于这个错误而失败
Traceback (most recent call last):
File "<ipython-input-3-67589181ed6a>", line 7, in <module>
mailServer.login(username, password)
File "/home/saber/miniconda3/envs/explore/lib/python3.6/smtplib.py", line 730, in login
raise last_exception
File "/home/saber/miniconda3/envs/explore/lib/python3.6/smtplib.py", line 721, in login
initial_response_ok=initial_response_ok)
File "/home/saber/miniconda3/envs/explore/lib/python3.6/smtplib.py", line 642, in auth
raise SMTPAuthenticationError(code, resp)
SMTPAuthenticationError: (535, b'5.7.3 Authentication unsuccessful [YQXPR0101CA0037.CANPRD01.PROD.OUTLOOK.COM]')
Any idea what might be the problem? 知道可能是什么问题吗?
Can you change the account to test it? 您可以更改帐户进行测试吗? Please refer to the following code:
请参考以下代码:
"""The first step is to create an SMTP object, each object is used for connection
with one server."""
import smtplib
server = smtplib.SMTP('smtp.gmail.com', 587)
#Next, log in to the server
server.login("youremailusername", "password")
#Send the mail
msg = "
Hello!" # The /n separates the message from the headers
server.sendmail("you@gmail.com", "target@example.com", msg)
Related link: Using Python to Send Email 相关链接: 使用Python发送电子邮件
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.