pythonoutlooksmtplibmail-server

Why am I unable to send more than 10 Emails using my SMTP server (OUTLOOK)


I have written an SMTP application in python, It is supposed to send at least 100+ emails as per the outlook limit but it gets the account banned after 10 mails. Can anyone explain to me what's wrong with the settings or the procedure I am using? I even tried using the app password.

The error I get after sending 10 emails:

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 RefuseQuota, ShowTierUpgrade. OutboundSpamException: WASCL UserAction verdict is not None. Actual verdict is RefuseQuota, ShowTierUpgrade.[EndDiagnosticData] [Hostname=TYZPR02MB5988.apoprd02.prod.outlook.com]')

Also, there is no pause between sending those emails, I log in to send the first and log out after the first one is sent. I do the same for every mail.

The code runs inside a for loop. So basically for every recipient.

My code:

selected_limit = limit_outlook
content = outlook_content
available_emails = list(outlook.keys())

# mail server parameters

smtpHost = 'smtp-mail.outlook.com'
smtpPort = 587
mailUname = details[0]  # Sender's username
mailPwd = details[1]  # App password
fromEmail = details[0]  # Sender's email

s = smtplib.SMTP(smtpHost, smtpPort)
s.connect(smtpHost, smtpPort)
s.starttls()
s.login(mailUname, mailPwd)

msg = MIMEMultipart()
msg['From'] = fromEmail
msg['To'] = ''.join([recepient])
msg['Subject'] = mailSubject
msg.attach(MIMEText(HtmlContent(content), 'html'))

msgText = msg.as_string()
sendErrs = s.sendmail(fromEmail, recepient, msgText)
s.quit()

Solution

  • I figured it out, I added a delay of 5 secs between each mail, Enabled POP and IMAP from outlook.com and I was able to send 30+ emails without any problems.

    I'll leave the details on how I enabled POP and IMAP for anyone who may have the same issue.

    Steps to Enable POP and IMAP:

    Select Settings> View all Outlook settings > Mail > Sync email.

    Under POP and IMAP, select Yes under Let devices and apps use POP.

    Select Save.