I want a view controller to only contain a text field and a send button. Is there a way to get the button to send the contents of the text field to a preset email address? Or is the only email capability MFMailComposeViewController
?
Asked
Active
Viewed 1,768 times
0
1 Answers
1
You can only send a mail through the MFMailComposeViewController
, but you could pass the value from your text field like the example below.
Place this code in your buttons action:
let toRecipients = ["mail@mail.com"]
let subject = "My Subject"
let body = textField.text // Your text fields text
mail = MFMailComposeViewController()
mail.mailComposeDelegate = self
mail.setToRecipients(toRecipients)
mail.setSubject(subject)
mail.setMessageBody(body, isHTML: false)
presentViewController(mail, animated: true, completion: nil)

Rashwan L
- 38,237
- 7
- 103
- 107
-
Hmm your code gave me an idea, and I was hoping there would be some sort of .send() function. That way I could just call that method as opposed to presenting the view controller. However I can't seem to see any of the functions/parameters that belong to MFMailComposeViewController in Apple's class reference page. It's all white. Where are you seeing these? – fossdeep Jan 05 '16 at 21:49
-
[This](https://developer.apple.com/library/ios/documentation/MessageUI/Reference/MFMailComposeViewController_class/) seems to be the only one available... – Rashwan L Jan 05 '16 at 21:53
-
Yeah that's the one I'm looking at. Is it nothing but white under the categories "Determining Mail Availability", etc.? Also wanted to add that, nowhere in the class reference page does it say you must import MessageUI, but it is needed. – fossdeep Jan 05 '16 at 21:58
-
Yes you need, tell me if you want me to update the post with everything you need. – Rashwan L Jan 05 '16 at 21:59
-
1I think it should be fine, unless there's something important you think I should add. Thanks! – fossdeep Jan 05 '16 at 22:01