How to send an email from an app in Swift

Oscar de la Hera Gomez
Two flowers that represent Swift and Xcode side by side. Beneath them sits the text "Send an Email."

A step by step tutorial on presenting a user with a preset email from an UIView or UIViewController in Swift.

We recommend that you clone our Open Source Swift Starter Project, checking out the main branch and carrying out the steps below. The changes can be found on the tutorial/email branch.

git clone git@github.com:delasign/swift-starter-project.git

Step One: Create the UI

A screenshot of Xcode showing the functionality that we added to make it show a button with the text "Send Email."

Make sure to add a button that will trigger the email function.

Step Two: Create the email functionality

A screenshot of Xcode showing the Email extension for the CustomUIView.swift. Code available below.

Create a new email extension for your UIView or UIViewController and paste in the code below.

Please note that if you are doing this within a UIViewController, you will not need the "vc" variable, as the UIViewController will be the vc variable.

Step Three: Call Send Email

A screenshot of Xcode highlighting how we have called send email from the callback of a button within a UIView.

Call the sendEmail function created in Step Two from the action created in Step One.

Step Four: Test

A screenshot of an iPhone demonstrating how an email has been drafted that matches the code shown in this tutorial.

Run the app in Xcode and make sure that the functionality works as expected.

Looking to learn more about things you can do with Swift and XCode ?

Search our blog to find educational content on learning how to use Swift and XCode.

Any Questions?

We are actively looking for feedback on how to improve this resource. Please send us a note to inquiries@delasign.com with any thoughts or feedback you may have.
delasign logo

Book a Free Consultation.

An icon of an email.

Click here to email us.

Fill in the details below to book a free consultation or to let us know about something else. Whatever it is, we are here to help.

How can we help you ?

Contact Details