Send attachment through Anvil's Gmail Service?

Hi, I’m using the Gmail service in Anvil quite successfully but I want to add an attachment to the emails sent via Anvil (they would be a Word Doc, or PDF stored in the data tables) and I’m not seeing ‘attachment’ as an option, like the ‘to’, ‘subject’, ‘text’ fields are.

Does anyone know if this is possible? Thanks! -Ian

Not a direct answer, but if the docs are on your google drive (or could be uploaded there) you could send a link to the doc in the body maybe?

(I don’t use the gmail services so I’m guessing slightly)

Hmm…I appreciate the suggestion but I really prefer an attachment to a link, plus I’d prefer not to store the file on both the anvil data table and google drive

Eventually I’ll move to a corporate email and use a dedicated mail service so maybe it’s not a big deal for the time being

Sure, was just a thought. I don’t use it myself.

I use mailgun.com for sending mail & attachments. Seems to work fine and they have a free tier.

Thanks, this mailgun looks great, 10,000 free emails a month should be more than enough headroom for me. Are you using it with Anvil, and if so, how is the integration?

Basically it’s this :

@anvil.server.callable
def send_email():
  resp = anvil.http.request(
      url="https://api.mailgun.net/v3/sandbox[redacted].mailgun.org/messages",
      method="POST",
      data={"from": "Mailgun Sandbox <postmaster@sandbox[redacted].mailgun.org>",
              "to": "David Wylie <david.wylie@telemix.co.uk>",
              "subject": "Hello David Wylie",
              "text": "Message sent through mailgun"},
      username="api",
      password="key-[redacted]")
  
  print("response = ",resp)
3 Likes