Live Chat

We'll need to share your messages (and your email address if you're logged in) with our live chat provider, Drift. Here's their privacy policy.

If you don't want to do this, you can email us instead at contact@anvil.works.

GMail

You can use Anvil to send email via your GMail account.

GMail is not intended for heavy usage. If you send more than ~100 messages per day through Anvil, consider using the Email Service

To send emails via your Gmail account, you first need to enable the Gmail service.

In the App Browser, click the ‘+’ next to Services, then select ‘Google API’. In the Google API dialog, expand the section named ‘Send email from your GMail address’, and click ‘Enable email’:

Enabling the sending of emails via Gmail in the Google API services dialog.

You’ll be prompted to log in and connect your GMail account.

Once you’ve enabled the GMail service, you can send emails via your GMail account from code. Here is a simple example, sending a text-only email to one address.

import anvil.google.mail

anvil.google.mail.send(
    to = "Sarah <sarah@example.com>",
    subject = "Meeting today",
    text = "See you at 5pm")

Here is a more complex example, illustrating all the possible parameters to anvil.google.mail.send:

  • from_address - The email address from which this email is sent. Must be a string. You can add a name to the From field with a string like "Name <email@address.com>". (You can specify any name, but the email address must be an address registered to this GMail account.)
  • to - The email address(es) this email is sent to. Can be a string or a list of strings.
  • cc - The email address(es) to which this email is CCed. Can be a string or a list of strings.
  • bcc - The email address(es) to which this email is Blind CCed. Can be a string or a list of strings.
  • subject - The subject line of the email
  • text - The plain text of the email. You must specify either text or html (or both).
  • html - An HTML-formatted version of the email. You must specify either text or html (or both).
anvil.google.mail.send(
   from_address = "Al <al@example.com>",
   to = ["sarah@example.com",
         "Bob <bob@example.com>"],
   cc = "jane@example.com",
   bcc = "mark@example.com",
   subject = "Meeting today",
   text =
   """
   Dear all,

   There will be a meeting today at 5pm.

   Best Regards,
   Joseph
   """,
   html =
   """
   Dear all,

   <p>There will be a meeting today at <b>5pm</b>.

   <p>Best regards,
   <p>Joseph
   """)