Anvil apps can send email with a single command. They can also receive email.
To send email, enable the Email service and simply run
anvil.email.send from the client or server.
anvil.email.send( to="email@example.com", from_address="support", from_name="MyApp Support", subject="Welcome to MyApp", html="<h1>Welcome!</h1>" )
To receive email, decorate a server function as a message handler using
@anvil.email.handle_message. Its first argument is then an object representing emails sent to the app.
You can reply to the incoming message using
reply. Store your message in a Data Table and you can display it on a Form to create a quick email client, such as this example app).
@anvil.email.handle_message def handle_incoming_emails(msg): msg.reply(text="Thank you for your message.") msg_row = app_tables.received_messages.add_row( from_addr=msg.envelope.from_address, to=msg.envelope.recipient, text=msg.text, html=msg.html ) for a in msg.attachments: app_tables.attachments.add_row( message=msg_row, attachment=a )