I’m very new to Anvil, but have been reading through the docs and tutorials. I don’t see a tutorial on sending emails, and the reference index shows a section for sending and receiving emails, but those links don’t go anywhere. The sending email with Gmail section suggests using an external service for sending larger quantities of email.
I also don’t see any cookbook entries for sending emails. What is the recommended way to send and receive emails through an Anvil app for a site that might exceed the Gmail limits?
You can use an external service such as Mailgun. I have an example somewhere, I’ll post it when I find it.
Ok,sending in its simplest form (account details redacted) :
@anvil.server.callable
def send_email():
resp = anvil.http.request(
url="https://api.mailgun.net/v3/sandboxxxxxxxxxxxxx.mailgun.org/messages",
method="POST",
data={"from": "MyTest <xxx@xxx.mydomain.com>",
"to": "XXXX <xxxxe@xxx.com>",
"subject": "Hello",
"text": "Congratulations, you just sent an email with Mailgun!"},
username="api",
password="key-xxxxxxxxxxxxxxxxxxxx")
I’ve not done receiving yet, but I’m sure it’s not hard.
2 Likes
Thanks, David! I appreciate the code sample, I can adapt that to whatever email service I end up with.
np. If you get stuck let me know.
In the event that someone else finds this topic without also finding the recent announcement about Anvil supported emails, here’s the blog post:
2 Likes
Suggestion: list it in “Announcements”.
Possibly my one gripe with Anvil - I never, ever see their announcements. I either stumble across them well after they’ve been posted or I catch a forum thread like this one. I had no idea that existed.
edit - hmm, though I’m ashamed to say I did miss it in the “services” … I must not have logged out/in for a while. I usually spot things like that 
edit edit - ah, I also see that post was today (blush) - I’m really not paying attention this week …
edit edit edit - almost on cue I got an email from @meredydd announcing the feature. I’m going back to bed …
2 Likes