Shanely
Shanely

Reputation: 123

Firestore + Swift; trigger email extension

I have an iOS app that I'm using with Cloud Firestore. I've read the documentation provided by firebase but I'm still unsure how this can be used with swift programming. Does anyone know or have experience with this firebase tigger function implementation with a swiftui app? How can I implement this?

Upvotes: 0

Views: 368

Answers (1)

Peter Friese
Peter Friese

Reputation: 7254

You can use the Trigger Email Extension to send an email when you add a new document to a Firestore collection.

To use this, you'll have to:

  1. Install the extension into your Firebase project via the console (see instructions here)
  2. Add a new document to the collection you specified when setting up the extension. Here is some sample code that shows how to do this in Swift:
db.collection("mail").addDocument(data: [
    "to": "[email protected]",
    "message": [
      "subject": "Hello from Firebase",
      "html": "This is an <code>HTML</code> email body."
    ]
]) { err in
    if let err = err {
        print("Error writing document: \(err)")
    } else {
        print("Document successfully written!")
    }
}

Upvotes: 2

Related Questions