简体   繁体   中英

sending Email using outlook through python

I am trying to send email through outlook using python I got 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]') but the strange thing is that this error not always occurs,sometimes It works and send mails.and

my code:

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')   

It just needed few googling to see that you encountered an exception related to your account, due to things like: not being verified, spamming, not upgrading, and more.

Sources: [1] , [2] , [3]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM