
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How can I send mail from an iPhone application?
To send an email from our application we'll need to use URL Schemes and some action on event of which the email will be sent. We can not actually send email from the application, unless it is an mailing application and we use MessageUI framework of iOS, but we can open some email app from our application with prefilled email and subject.
We'll see both the ways of doing this.
Let's see how we can open the MAIL app of iOS with an example.
Create a project and on its first view controller
add a button and change it's text to open "open e-mail", create its action in the ViewController.swift class
Add another button call it "open MF mail", and create it's action too.
Method 1 − Using URL Scheme and other mailing app
func sendEmail(email:String) { if let url = URL(string: "mailto:\(email)") { if #available(iOS 10.0, *) { UIApplication.shared.open(url) } else { UIApplication.shared.openURL(url) } } }
This function can be called to send email to some email id, call this function inside the body of First button "open e-mail", below is the result
Method 2 − Using MFMailCompose of MessageUI Framework
func sendMFmail(email: String) { let mailVC = MFMailComposeViewController() mailVC.mailComposeDelegate = self mailVC.setToRecipients([email]) mailVC.setSubject("Testing sending email") mailVC.setMessageBody("Test Body of email", isHTML: false) present(mailVC, animated: true, completion: nil) }
This function can be called inside the body of "open MF mail" button's action similar to method one, and it produces the following result.
Note - These apps can not be run on simulator because mail is not supported in simulator and you need an actual device.
- Related Questions & Answers
- How can I send emails using gmail from my Android application?
- How can I send emails using gmail from my Android application using Kotlin?
- How can I send emails using gmail from my Android application using Kotlin Programming?
- Send mail from your Gmail account using Python
- Send mail with attachment from your Gmail account using Python
- How to exit iPhone application gracefully?
- How can I set an icon for my iOS application?
- How can I set an icon for my Android application?
- How to launch any arbitrary iPhone application from within another app?
- How should I validate an e-mail address in Android?
- What is an Electronic Mail (E-Mail)?
- How can I develop for iPhone using a Windows development machine?
- How to Launch an application from another application on Android
- How should I validate an e-mail address in Android using Kotlin?.
- How can I send radio button value in PHP using JavaScript?