---
title: MFMailComposeViewController
framework: Message UI
role: symbol
role_heading: Class
platforms: [iOS 3.0+, iPadOS 3.0+, Mac Catalyst 13.1+, visionOS 1.0+]
path: messageui/mfmailcomposeviewcontroller
---

# MFMailComposeViewController

A standard view controller, whose interface lets the user manage, edit, and send email messages.

## Declaration

```swift
@MainActor class MFMailComposeViewController
```

## Overview

Overview Use this view controller to display a standard email interface inside your app. Before presenting the interface, populate the fields with initial values for the subject, email recipients, body text, and attachments of the email. After presenting the interface, the person can edit your initial values before sending the email. The composition interface doesn’t guarantee the delivery of your email message; it only lets you construct the initial message and present it for user approval. The person may opt to cancel the composition interface which discards the message and its contents. If the person opts to send the message, the message queues in the user’s Mail app outbox. The Mail app is ultimately responsible for sending the message.

important: You must not modify the view hierarchy presented by this view controller. However, you can customize the appearance of the interface using the UIAppearance protocol. An alternate way to compose emails is to create and open a URL that uses the mailto scheme. URLs of that type go directly to the built-in Mail app, which uses your URL to configure a message. For information about the structure of mailto URLs, see Apple URL Scheme Reference. Checking the availability of the composition interface Before presenting the mail compose view controller, always call the canSendMail() method to see if the person configured the current device to send email. If the person’s device isn’t set up for the delivery of email, you can notify the person or disable the email dispatch features in your application. You shouldn’t attempt to use this interface if the canSendMail() method returns false. Configuring and displaying the composition interface After verifying that mail services are available, you can create and configure the mail composition view controller and then present it as any other view controller. Use the methods of this class to specify the subject, recipients, and message body of the email, including any attachments you want to send with the message. The sample code below shows how to configure the composition interface and present it modally. Always assign a delegate to the mailComposeDelegate property, because the delegate is responsible for dismissing the composition interface later. important: After presenting a mail compose view controller, the system ignores any attempts to modify the email using the methods of this class. The user can still edit the content of the email, but your app can’t. Therefore, always configure the fields of your email before presenting the view controller. The mail compose view controller isn’t dismissed automatically. When the user taps the buttons to send the email or cancel the interface, the mail compose view controller calls the mailComposeController(_:didFinishWith:error:) method of its delegate. Your implementation of that method must dismiss the view controller explicitly, as shown in sample code below. You can also use this method to check the result of the operation. The user can delete a queued message before it’s sent. Although the view controller reports the success or failure of the operation to its delegate, this class doesn’t provide a way for you to verify if the email sent. For more information on how to present and dismiss view controllers, see View Controller Programming Guide for iOS.

## Topics

### Responding to the view controller dismissal

- [mailComposeDelegate](messageui/mfmailcomposeviewcontroller/mailcomposedelegate.md)
- [MFMailComposeViewControllerDelegate](messageui/mfmailcomposeviewcontrollerdelegate.md)

### Determining mail availability

- [canSendMail()](messageui/mfmailcomposeviewcontroller/cansendmail().md)

### Setting mail fields programmatically

- [setSubject(_:)](messageui/mfmailcomposeviewcontroller/setsubject(_:).md)
- [setToRecipients(_:)](messageui/mfmailcomposeviewcontroller/settorecipients(_:).md)
- [setCcRecipients(_:)](messageui/mfmailcomposeviewcontroller/setccrecipients(_:).md)
- [setBccRecipients(_:)](messageui/mfmailcomposeviewcontroller/setbccrecipients(_:).md)
- [setMessageBody(_:isHTML:)](messageui/mfmailcomposeviewcontroller/setmessagebody(_:ishtml:).md)
- [addAttachmentData(_:mimeType:fileName:)](messageui/mfmailcomposeviewcontroller/addattachmentdata(_:mimetype:filename:).md)
- [setPreferredSendingEmailAddress(_:)](messageui/mfmailcomposeviewcontroller/setpreferredsendingemailaddress(_:).md)

### Responding to errors

- [MFMailComposeError](messageui/mfmailcomposeerror.md)
- [MFMailComposeErrorDomain](messageui/mfmailcomposeerrordomain.md)
- [MFMailComposeError.Code](messageui/mfmailcomposeerror/code.md)

### Instance Methods

- [insertCollaborationItemProvider(_:completionHandler:)](messageui/mfmailcomposeviewcontroller/insertcollaborationitemprovider(_:completionhandler:).md)

## Relationships

### Inherits From

- [UINavigationController](uikit/uinavigationcontroller.md)

### Conforms To

- [CVarArg](swift/cvararg.md)
- [CustomDebugStringConvertible](swift/customdebugstringconvertible.md)
- [CustomStringConvertible](swift/customstringconvertible.md)
- [Equatable](swift/equatable.md)
- [Hashable](swift/hashable.md)
- [NSCoding](foundation/nscoding.md)
- [NSExtensionRequestHandling](foundation/nsextensionrequesthandling.md)
- [NSObjectProtocol](objectivec/nsobjectprotocol.md)
- [NSTouchBarProvider](appkit/nstouchbarprovider.md)
- [Sendable](swift/sendable.md)
- [SendableMetatype](swift/sendablemetatype.md)
- [UIActivityItemsConfigurationProviding](uikit/uiactivityitemsconfigurationproviding.md)
- [UIAppearanceContainer](uikit/uiappearancecontainer.md)
- [UIContentContainer](uikit/uicontentcontainer.md)
- [UIFocusEnvironment](uikit/uifocusenvironment.md)
- [UIPasteConfigurationSupporting](uikit/uipasteconfigurationsupporting.md)
- [UIResponderStandardEditActions](uikit/uiresponderstandardeditactions.md)
- [UIStateRestoring](uikit/uistaterestoring.md)
- [UITraitChangeObservable](uikit/uitraitchangeobservable-67e94.md)
- [UITraitEnvironment](uikit/uitraitenvironment.md)
- [UIUserActivityRestoring](uikit/uiuseractivityrestoring.md)
