簡體   English   中英

通過 python 使用 Outlook 發送電子郵件

[英]sending Email using outlook through python

我正在嘗試使用 python 通過 Outlook 發送電子郵件我得到了Traceback (most recent call last): File "c:\Users\Variable\Documents\python_files\learning_new\sending_email.py", line 23, in <module> session.sendmail(sender_address, receiver_address, text) File "C:\Users\Variable\AppData\Local\Programs\Python\Python310\lib\smtplib.py", line 908, in sendmail raise SMTPDataError(code, resp) smtplib.SMTPDataError: (554, b'5.2.0 STOREDRV.Submission.Exception:OutboundSpamException; Failed to process message due to a permanent exception with message [BeginDiagnosticData]WASCL UserAction verdict is not None. Actual verdict is Suspend, ShowTierUpgrade. OutboundSpamException: WASCL UserAction verdict is not None. Actual verdict is Suspend, ShowTierUpgrade.[EndDiagnosticData] [Hostname=PAXP193MB1710.EURP193.PROD.OUTLOOK.COM]')但奇怪的是這個錯誤並不總是發生,有時它可以工作並發送郵件。

我的代碼:

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.
Thank You'''
#The mail addresses and password
sender_address = 'Fahe_em@outlook.com'
sender_pass = '*********'
receiver_address = 'fah909190@gmail.com'
#Setup the MIME
message = MIMEMultipart()
message['From'] = sender_address
message['To'] = receiver_address
message['Subject'] = 'A test mail sent by Python. It has an attachment.'   #The subject line
#The body and the attachments for the mail
message.attach(MIMEText(mail_content, 'plain'))
#Create SMTP session for sending the mail
session = smtplib.SMTP('smtp.office365.com', 587) #use gmail with port
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')   

只需很少的谷歌搜索就可以看到您遇到了與您的帳戶相關的異常,原因如下:未經過驗證、垃圾郵件、未升級等。

資料來源: [1][2][3]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM