Email not being sent

I am trying to send an email to my app

I have sent a test to the app domain and am only getting errors back in my personal email

Code Sample:

import anvil.email
import anvil.server

@anvil.email.handle_message()
def message_handler(msg):
    print("Message received from %s" % msg.addressees.from_address.raw_value)
    msg.reply(text="Thanks for your email!")

error i recieve via email when i try to send

Error Details
Error: 550 5.1.351 Remote server returned unknown recipient or mailbox unavailable → 550 permanent failure for one or more recipients (test@rs2f6ws2wpgaymqh.anvil.app:553 test@rs2f6ws2wpgaymqh.anvil.app address unknown.)


Message rejected by: mx-outbound45-4.us-east-2c.ess.aws.cudaops.com

(The bold is mine.)

So it is being sent. But the receiving system is rejecting it, and saying why.

This gives you a number of different things that you can check, such as

  • the email address that you are sending to
  • the domain that you are sending to

to make sure that both actually exist at your intended destination.

now im getting this and to be clear this is in the email account im using to test the site – so im sending emails from an external email box (my outlook) and getting an error in outlook saying the site doesnt exist or it was doiing that – now it is doing this

Your message to anything@twitter-route.anvil.app couldn’t be delivered.
twitter-route.anvil.app suspects your message is spam and rejected it.
scrockford Office 365 twitter-route.anvil… . .
Sender Action Required
Messages suspected as spam

How to Fix It
Try to modify your message, or change how you’re sending the message, using the guidance in this article: Bulk E-mailing Best Practices for Senders Using Forefront Online Protection for Exchange. Then resend your message.
If you continue to experience the problem, contact the recipient by some other means (by phone, for example) and ask them to ask their email admin to add your email address, or your domain name, to their allowed senders list.

Was this helpful? Send feedback to Microsoft.

More Info for Email Admins
Status code: 550 5.7.350

When Office 365 tried to send the message to the recipient (outside Office 365), the recipient’s email server (or email filtering service) suspected the sender’s message is spam.

If the sender can’t fix the problem by modifying their message, contact the recipient’s email admin and ask them to add your domain name, or the sender’s email address, to their list of allowed senders.

Although the sender may be able to alter the message contents to fix this issue, it’s likely that only the recipient’s email admin can fix this problem. Unfortunately, Office 365 Support is unlikely to be able to help fix these kinds of externally reported errors.

Original Message Details
Created Date: 1/18/2024 9:35:08 PM
Sender Address: scrockford@llrlaw.com
Recipient Address: anything@twitter-route.anvil.app
Subject: hi

Error Details
Error: 550 5.7.350 Remote server returned message detected as spam → 550 permanent failure for one or more recipients (anything@twitter-route.anvil.app:551 This application cannot handle incoming email)
Message rejected by: mx-outbound45-197.us-east-2c.ess.aws.cudaops.com

Notification Details
Sent by: CH2PR04MB6572.namprd04.prod.outlook.com

This looks much more informative.

I haven’t used my Anvil apps to receive emails, but others here have, and may have some hints, tips, or questions for you. For example, what features have you used at the sending end to assure the receiving email server that the message is not spam?

Use anvil for both sending and receiving fairly regularly. Never really experienced a problem, barring some that were resolved with a custom domain and DMARC / DKIM.

If you search those acronyms individually in the forum there are some handy threads.