I can successfully connect to smtp.office365.com with OAuth and browse a mailbox but when I go to send mail I get a "Blocked" error

utiladmin 0 Reputation points
2025-05-30T03:36:53.65+00:00

I can give the code to a colleague and he can run it and it works fine from his machine in India. I receive the colleague's email test fine to an outside mail server, which is a GoDaddy hosted email machine. But, when I try to run it I get this error message from 3 different machines/servers:

The remote server returned an error: (500) Internal Server Error. {"code":"RequestBlocked","message":"Request is preemptively blocked. Early service protection triggered. Please try again after 6.775 seconds"}

This one is from a server with a static IP address that we've had for more than 10 years. I also get the same error from an Azure VM. That one does not have a static IP. I also have the issue with my development computer at home. Same error, all three machines. I performed these tests within the last 2 hours to my office365 email server.

See the code below:

(EDIT: removed tenant, EASendMail license code and other identifying info)

  Dim oServer As New EASendMail.SmtpServer("smtp.office365.com", 587)
  oServer.Protocol = EASendMail.ServerProtocol.ExchangeEWS
  oServer.User = strUserName
  oServer.Password = parser.AccessToken
  ' User OAUTH 2.0
  oServer.AuthType = ServerAuthType.AuthXOAUTH2
  'oServer.Port = 587
  ' Enable SSL/TLS connection,
  oServer.ConnectType = SmtpConnectType.ConnectSTARTTLS
  Dim oMail As New EASendMail.SmtpMail("<licenseCode>")
  ' Your office 365 email address
  oMail.From = strUserName
  ' Set recipient email address, please change it to yours
  oMail.To = "******@fabryfamily.com"
  ' Set email subject
  oMail.Subject = "test email from office 365 account"
  ' Set email body
  oMail.TextBody = "this is a test email sent from VB.NET project with O365"
  Dim smtp = New EASendMail.SmtpClient()
  smtp.SendMail(oServer, oMail)    'This is where the error occurs


Developer technologies | VB
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. utiladmin 0 Reputation points
    2025-06-06T05:24:28.76+00:00

    What ended up solving the problem for me was changing from using manual HTTP POST to get an OAuth 2.0 access token from Microsoft Identity Platform (Azure AD) using the client credentials grant to authenticate via OAuth2 when sending email through Microsoft 365 (Office 365) SMTP. Instead I switched to using the Microsoft Authentication Library (MSAL) to get an access token via the client credentials flow for Microsoft Graph API.

    0 comments No comments

  2. Omkara Varshitha Kunapalli (INFOSYS LIMITED) 1,985 Reputation points Microsoft External Staff
    2025-11-18T07:24:08.19+00:00

    Hello hope your doing well thanks for reaching out !
    Set protocol to SMTP: Change to oServer.Protocol = EASendMail.ServerProtocol.SMTP.

    1. Use STARTTLS on 587: Keep smtp.office365.com, port 587, oServer.ConnectType = SmtpConnectType.ConnectSTARTTLS.
    2. Auth with OAuth2: Ensure oServer.AuthType = ServerAuthType.AuthXOAUTH2 and pass the valid access token.
    3. Enable SMTP AUTH: In Exchange Online, turn on SMTP AUTH for the sending mailbox.
    4. Send slowly: Try one email, then wait 1–2 minutes before retrying; implement backoff if you see “RequestBlocked.”
    5. Use clean network/IP: Test from a single machine; ensure your IP has reverse DNS/PTR and matching domain in EHLO.
    6. Update TLS: Make sure the OS supports TLS 1.2+; update if needed.
    7. If still blocked: Switch to Microsoft Graph sendMail API or ask your admin to review anti-abuse/throttling for your IP.

     

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.