Skip to content

4. Passing Predefined Email Data

Gabriel Theodoropoulos edited this page Jul 22, 2021 · 1 revision

It's often necessary to provide predefined values or data to the email that users will compose and send. For example, you may want a default subject or a specific recipient to prefill the respective fields in the email.

To do so, pass an EmailData instance to the emailComposer method. It's often handy to create that instance before passing it to the view modifier, providing one or more values and data you wish. In the next example, an EmailData instance is initialized in the view, containing the email's subject and a recipient:

struct ContentView: View {
    ...
    
    let emailData = EmailData(subject: "Hi there!",
                              recipients: ["some@recipient.xyz"])
    
    var body: some View {
        Button("Send email") { ... }
        .emailComposer(isPresented: $showEmailComposer,
                       emailData: emailData)
    }
}

Take a look at the EmailData type to find out more.

Clone this wiki locally