我想使用公司帐户发送电子邮件。但是,我在Python中收到以下错误:
SMTPAuthenticationError: 550, b'5.2.1 Mailbox cannot be accessed
如果我在Outlook中打开公司帐户,则可以使用Powershell脚本通过它发送电子邮件。但是Python脚本只会给我上面的错误。
以下是我的python代码:
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
mail_content = "Hello, This is a simple mail. There is only text, no \
attachments are there The mail is sent using Python SMTP library"
sender_address = 'corporate_email_account'
sender_pass = 'XXXX'
receiver_address = 'corporate_email_account'
message = MIMEMultipart()
message['From'] = sender_address
message['To'] = receiver_address
message['Subject'] = 'A test mail sent by Python. It has an attachment.'
message.attach(MIMEText(mail_content, 'plain'))
session = smtplib.SMTP('smtp.office365.com', 587)
session.starttls() #enable security
session.login(sender_address, sender_pass) #login with mail_id and password
text = message.as_string()
session.sendmail(sender_address, receiver_address, text)
session.quit()
print('Mail Sent')
为什么Python无法发送电子邮件?这可能是防火墙问题,还是Microsoft不允许python脚本中的这种行为,但是Powershell脚本可以吗?