© 2013 All rights reserved.

Sending a message or email from iOS devices

Often you need your application to be able to send users emails or messages. In iOS, this can be done simply by MessageUI framework.

At the end of the article you can download the whole example. Now we assume that we know the email address or phone number of the user to whom the message we send.

The interface might look like this:


iphone send sms


Adding Message Framework into sources

The first step you need to do is add the necessary frameworks to the project. In this case the only need MessageUI.framework

We’ll do it as well as the following figure


iphone send sms


Creating a header file

Header files will be in this case include two protocols, that declared methods which can be Implemented.


  • MFMailComposeViewControllerDelegate
  • MFMessageComposeViewControllerDelegate

Interface in a header file might look like the following code

Sending Email

If you have prepared all the necessary variables, we can simply create a new composer.

In this case we assume that we have a ready variables: messageBody (message text), messageSubject (message subject) and email (email address to recipient).


Finally, open the dialog window for sending email.

Now we have to check what has happened with our email, and whether it was sent. Write the method mailComposeController, which contains information about the result.

Examples include a method makeAlert, here you will find the prime example (here)


iphone send sms


Sending message

Sending messages is similar to that sending emails, but with the difference that we use MFMessageComposeViewController.

The main difference is that the device may not be able to send messages, this we can simply verify with the following code:

In the case that you can send messages, you can prepare MFMessageComposeViewController:

In this case we assume that we have a ready variables: messageBody (message text) and phone (phone number)


Finally, open the dialog for sending messages:

The last thing is that we must check whether the message was sent or not. We create function MessageComposeViewController that contains the result.

It may look like this:

Important is call DismissViewControllerAnimated. The application will return back to our view.


iphone send sms


Complete example

Complete example can be found on github. Also contains a simple interface to enter a phone number and email.

Comments are closed for this page

Nice Article.

Hi, i am programmer from the Czech Republic. I love web development (Ruby, Ruby on Rails, PHP, Nette) and iOS development (Objective-C, Cocoa).
To cooperate, here is my phone:
+420 608 836