First time email set up, "Relay access denied"

What I’m trying to do:

This is a first time email setup for a custom domain. Trying to receive email from a simple gmail account test.

What I’ve tried and what’s not working:

Send an simple test email from a gmail account. This is the checklist I’ve run through:

1. Assure the app has the email component configured.
App has Email component added. I can see the message about being able to send to “anything@” my custom domain.

2. App has a server-module with an email-handling function defined.
Simplest example for a server module function from Meredyd’s online post about this:

@anvil.email.handle_message
def incoming_email(msg):
app_tables.received_messages.add_row(
from_addr=msg.envelope.from_address,
text_content=msg.text
)
msg.reply(text="Thank you for your message.")

3. Data table defined “received_messages” with server access.
Has identical fields as the online example.

4. App is published to the master branch.

5. A record is configured in the domain console.
Yes, an “A” record is set up to point to 52.56.203.177

Still not able to receive email, the automated response to my gmail test is:
Error: 554 5.7.1 anything@ ... Relay access denied

Again, this is coming as an automated reply to a sample email sent to the domain.

Replying to your specific questions:
What domain was your app on before? Are the emails now being sent to the new domain?
This is a completely new custom domain. I have another app with a custom domain that’s working fine and copied the exact same processes (A record, handler function, app config)

How is your domain configured (eg are you using something funny like Cloudflare or just straight DNS)?
This is simple godaddy domain just like the other example app. Straight DNS.

You say your emails aren’t appearing in a received_messages table, which I assume is a data table. Do you see new messages arriving in the App Logs and the just don’t make it into your data table, or are they not showing up at all?
Yep, simple data table. The messages don’t show up in the app logs at all. Should they be there? I’ve never seen email received show up in an app log.

1 Like

Hi @mr_alex,

Do you still see the error if you remove the msg.reply(...) call from your incoming_email server function? That will help narrow down whether it’s the receiving or sending that is failing - because if your @handle_message function raises an exception, the incoming email will be rejected with a 554 error. Let’s work out whether the initial email is making it to Anvil, then go from there!

Do i still see the error if we remove the msg.reply(...) from the server function? Yes, the failure reply came back to my gmail account almost instantly even without this.

One thing I’ve noticed today is that my other perfectly functioning app shows “incoming email” in the App Sessions log. This is not shown in this current app. No where are the incoming emails or related errors shown in the log after 25+ attempts.

1 Like

Thanks - that’s helpful! At least now we have identified that the email is never reaching Anvil. So we need to look to DNS configuration and other factors. Firstly, do you have any MX Records on your custom domain, or just the single A Record pointing to Anvil’s IP address? Do you see the same problem no matter where you email from, including other source accounts with different providers?

There are no MX records set up, just the single A record. Yes, it’s the same problem no matter where I email from

So there is a default email setting with the registrar I’m using, had to turn that off. That fixed it.

2 Likes