Chapter 5:
Send Emails

We’ll use the Email Service to send you an email each time someone leaves feedback.

Step 1: Add the Email Service

Add a new Service, the same way you added the Data Tables service, and select ‘Email’:

Adding a service
Adding the Email Service

Now you’ve enabled the Email Service, it’s just one line of Python to send an email.

Step 2: Call the send function

Go to your Server Module, and modify your add_feedback function to look like this. Remember to change the address to your email address!

@anvil.server.callable
def add_feedback(name, email, feedback):
  app_tables.feedback.add_row(
    name=name, 
    email=email, 
    feedback=feedback, 
    created=datetime.now()
  )
  # Send yourself an email each time feedback is submitted
  anvil.email.send(to="noreply@anvil.works", # Change this to your email address!
                   subject=f"Feedback from {name}",
                   text=f"""
  A new person has filled out the feedback form!

  Name: {name}
  Email address: {email}
  Feedback:
  {feedback}
  """)

Step 3: Run your app

Let’s run your app again! Click the ‘Run’ button at the top of the screen, fill in a name, email address, and some feedback and click Submit.

When you click Submit, you’ll receive an email letting you know someone has filled out your feedback form.

And that’s it. You’ve just built a working database-backed feedback app in Anvil.

You now have a solid foundation in Anvil.

Your app is already live on the internet. Go to Publish App in the Gear Menu gear icon for details.

You can also use the following link to clone the finished app and explore it yourself:

What next?

Head to the Anvil Learning Centre for more tutorials, or head to our examples page to see how to build some complex apps in Anvil.

Congratulations!

Congratulations! You’ve built and shipped a database-backed web application!

You also now have a solid foundation in Anvil.


What next?

Head to the Anvil Learning Centre for more tutorials, or head to our examples page to learn how to build more complex apps in Anvil.