Open eMail from App with predefined text in iOS
Hello i want to open the eMail program from my App and the body should already be defined. I can open the eMail but don't know how to define the body of the eMail as a given Parameter to show a given standard text. Anyone can help? Heres the code i use to open Email:
//EMAIL
let email = "foo@bar.com"
let urlEMail = NSURL(string: "mailto:(email)")
if UIApplication.sharedApplication().canOpenURL(urlEMail!) {
UIApplication.sharedApplication().openURL(urlEMail!)
} else {
print("Ups")
}
ios swift email url-scheme
add a comment |
Hello i want to open the eMail program from my App and the body should already be defined. I can open the eMail but don't know how to define the body of the eMail as a given Parameter to show a given standard text. Anyone can help? Heres the code i use to open Email:
//EMAIL
let email = "foo@bar.com"
let urlEMail = NSURL(string: "mailto:(email)")
if UIApplication.sharedApplication().canOpenURL(urlEMail!) {
UIApplication.sharedApplication().openURL(urlEMail!)
} else {
print("Ups")
}
ios swift email url-scheme
Do some research on themailto:
URL scheme. You can provide "to" addresses, "cc" addresses, a subject, and the message body. But of course the best option is to do what the answers below suggest.
– rmaddy
Nov 13 '15 at 14:53
add a comment |
Hello i want to open the eMail program from my App and the body should already be defined. I can open the eMail but don't know how to define the body of the eMail as a given Parameter to show a given standard text. Anyone can help? Heres the code i use to open Email:
//EMAIL
let email = "foo@bar.com"
let urlEMail = NSURL(string: "mailto:(email)")
if UIApplication.sharedApplication().canOpenURL(urlEMail!) {
UIApplication.sharedApplication().openURL(urlEMail!)
} else {
print("Ups")
}
ios swift email url-scheme
Hello i want to open the eMail program from my App and the body should already be defined. I can open the eMail but don't know how to define the body of the eMail as a given Parameter to show a given standard text. Anyone can help? Heres the code i use to open Email:
//EMAIL
let email = "foo@bar.com"
let urlEMail = NSURL(string: "mailto:(email)")
if UIApplication.sharedApplication().canOpenURL(urlEMail!) {
UIApplication.sharedApplication().openURL(urlEMail!)
} else {
print("Ups")
}
ios swift email url-scheme
ios swift email url-scheme
edited Nov 13 '15 at 16:45
Stefan
3,65981942
3,65981942
asked Nov 13 '15 at 14:15
JanScottJanScott
102110
102110
Do some research on themailto:
URL scheme. You can provide "to" addresses, "cc" addresses, a subject, and the message body. But of course the best option is to do what the answers below suggest.
– rmaddy
Nov 13 '15 at 14:53
add a comment |
Do some research on themailto:
URL scheme. You can provide "to" addresses, "cc" addresses, a subject, and the message body. But of course the best option is to do what the answers below suggest.
– rmaddy
Nov 13 '15 at 14:53
Do some research on the
mailto:
URL scheme. You can provide "to" addresses, "cc" addresses, a subject, and the message body. But of course the best option is to do what the answers below suggest.– rmaddy
Nov 13 '15 at 14:53
Do some research on the
mailto:
URL scheme. You can provide "to" addresses, "cc" addresses, a subject, and the message body. But of course the best option is to do what the answers below suggest.– rmaddy
Nov 13 '15 at 14:53
add a comment |
6 Answers
6
active
oldest
votes
You can do it using MFMailComposeViewController
:
import MessageUI
let mailComposerVC = MFMailComposeViewController()
mailComposerVC.mailComposeDelegate = self
mailComposerVC.setToRecipients(["email@email.com"])
mailComposerVC.setSubject("Subject")
mailComposerVC.setMessageBody("Body", isHTML: false)
self.presentViewController(mailComposerVC, animated: true, completion: nil)
Also, you need to implement mailComposeController:didFinishWithResult:error:
from MFMailComposeViewControllerDelegate
where you should dismiss MFMailComposeViewController
5
Before you create your mailComposerVC it is not a bad idea to check if you actually can send an email usingMFMailComposeViewController.canSendMail()
– Au Ris
May 2 '17 at 13:18
add a comment |
If you'd like to open the built-in email app as opposed to showing the MFMailComposeViewController
as has been mentioned by others, you could construct a mailto:
link like this:
let subject = "My subject"
let body = "The awesome body of my email."
let encodedParams = "subject=(subject)&body=(body)".stringByAddingPercentEncodingWithAllowedCharacters(.URLQueryAllowedCharacterSet())
let url = "mailto:foo@bar.com?(encodedParams)"
if let emailURL = NSURL(url) {
if UIApplication.sharedApplication().canOpenURL(emailURL) {
UIApplication.sharedApplication().openURL(emailURL)
}
}
Just to save anyone typing, for 2016 the syntax has changed slightly:
let subject = "Some subject"
let body = "Plenty of email body."
let coded = "mailto:blah@blah.com?subject=(subject)&body=(body)".stringByAddingPercentEncodingWithAllowedCharacters(.URLQueryAllowedCharacterSet())
if let emailURL:NSURL = NSURL(string: coded!)
{
if UIApplication.sharedApplication().canOpenURL(emailURL)
{
UIApplication.sharedApplication().openURL(emailURL)
}
the actual correct answer to the question on the page! thanks man! :)
– Fattie
Jul 27 '16 at 18:36
add a comment |
Swift 3 Version
let subject = "Some subject"
let body = "Plenty of email body."
let coded = "mailto:blah@blah.com?subject=(subject)&body=(body)".addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)
if let emailURL: NSURL = NSURL(string: coded!) {
if UIApplication.shared.canOpenURL(emailURL as URL) {
UIApplication.shared.openURL(emailURL as URL)
}
}
add a comment |
Swift 4.0
let email = "feedback@company.com"
let subject = "subject"
let bodyText = "Please provide information that will help us to serve you better"
if MFMailComposeViewController.canSendMail() {
let mailComposerVC = MFMailComposeViewController()
mailComposerVC.mailComposeDelegate = self
mailComposerVC.setToRecipients([email])
mailComposerVC.setSubject(subject)
mailComposerVC.setMessageBody(bodyText, isHTML: true)
self.present(mailComposerVC, animated: true, completion: nil)
} else {
let coded = "mailto:(email)?subject=(subject)&body=(bodyText)".addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)
if let emailURL = URL(string: coded!)
{
if UIApplication.shared.canOpenURL(emailURL)
{
UIApplication.shared.open(emailURL, options: [:], completionHandler: { (result) in
if !result {
// show some Toast or error alert
//("Your device is not currently configured to send mail.")
}
})
}
}
}
add a comment |
Use the MFMailComposeViewController
like this:
Import the MessageUI
import MessageUI
Add the delegate to your class:
class myClass: UIViewController, MFMailComposeViewControllerDelegate {}
Configure the email preset you want to have
let mail = MFMailComposeViewController()
mail.mailComposeDelegate = self
mail.setSubject("Subject")
mail.setMessageBody("Body", isHTML: true)
mail.setToRecipients(["my@email.com"])
presentViewController(mail, animated: true, completion: nil)
Put this method in your code:
func mailComposeController(controller: MFMailComposeViewController!, didFinishWithResult result: MFMailComposeResult, error: NSError!) {
dismissViewControllerAnimated(true, completion: nil)
}
There you go, works now.
2
do not forget check: if MFMailComposeViewController.canSendMail() {...
– djdance
Jan 5 '16 at 18:24
add a comment |
I suggest to use Apple's way, which you can find in official documentation about MFMailComposeViewController. It opens a modal view controller with the email, which is dismissed after sending. Thus user stays in your app.
1
OP asked for Swift code, your reference displays Obj-C instead.
– LinusGeffarth
Nov 13 '15 at 14:57
1
The link leads to Apple's documentation, where are all information, which could Jan possibly need, not only specific parts (methods/properties). Apple has the sample code only in ObjC in this case, but it could be easily translated to Swift.
– David Rysanek
Nov 14 '15 at 10:14
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f33694771%2fopen-email-from-app-with-predefined-text-in-ios%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
6 Answers
6
active
oldest
votes
6 Answers
6
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can do it using MFMailComposeViewController
:
import MessageUI
let mailComposerVC = MFMailComposeViewController()
mailComposerVC.mailComposeDelegate = self
mailComposerVC.setToRecipients(["email@email.com"])
mailComposerVC.setSubject("Subject")
mailComposerVC.setMessageBody("Body", isHTML: false)
self.presentViewController(mailComposerVC, animated: true, completion: nil)
Also, you need to implement mailComposeController:didFinishWithResult:error:
from MFMailComposeViewControllerDelegate
where you should dismiss MFMailComposeViewController
5
Before you create your mailComposerVC it is not a bad idea to check if you actually can send an email usingMFMailComposeViewController.canSendMail()
– Au Ris
May 2 '17 at 13:18
add a comment |
You can do it using MFMailComposeViewController
:
import MessageUI
let mailComposerVC = MFMailComposeViewController()
mailComposerVC.mailComposeDelegate = self
mailComposerVC.setToRecipients(["email@email.com"])
mailComposerVC.setSubject("Subject")
mailComposerVC.setMessageBody("Body", isHTML: false)
self.presentViewController(mailComposerVC, animated: true, completion: nil)
Also, you need to implement mailComposeController:didFinishWithResult:error:
from MFMailComposeViewControllerDelegate
where you should dismiss MFMailComposeViewController
5
Before you create your mailComposerVC it is not a bad idea to check if you actually can send an email usingMFMailComposeViewController.canSendMail()
– Au Ris
May 2 '17 at 13:18
add a comment |
You can do it using MFMailComposeViewController
:
import MessageUI
let mailComposerVC = MFMailComposeViewController()
mailComposerVC.mailComposeDelegate = self
mailComposerVC.setToRecipients(["email@email.com"])
mailComposerVC.setSubject("Subject")
mailComposerVC.setMessageBody("Body", isHTML: false)
self.presentViewController(mailComposerVC, animated: true, completion: nil)
Also, you need to implement mailComposeController:didFinishWithResult:error:
from MFMailComposeViewControllerDelegate
where you should dismiss MFMailComposeViewController
You can do it using MFMailComposeViewController
:
import MessageUI
let mailComposerVC = MFMailComposeViewController()
mailComposerVC.mailComposeDelegate = self
mailComposerVC.setToRecipients(["email@email.com"])
mailComposerVC.setSubject("Subject")
mailComposerVC.setMessageBody("Body", isHTML: false)
self.presentViewController(mailComposerVC, animated: true, completion: nil)
Also, you need to implement mailComposeController:didFinishWithResult:error:
from MFMailComposeViewControllerDelegate
where you should dismiss MFMailComposeViewController
edited Nov 13 '18 at 12:05
EderYif
682820
682820
answered Nov 13 '15 at 14:22
Michał KasprzykMichał Kasprzyk
18917
18917
5
Before you create your mailComposerVC it is not a bad idea to check if you actually can send an email usingMFMailComposeViewController.canSendMail()
– Au Ris
May 2 '17 at 13:18
add a comment |
5
Before you create your mailComposerVC it is not a bad idea to check if you actually can send an email usingMFMailComposeViewController.canSendMail()
– Au Ris
May 2 '17 at 13:18
5
5
Before you create your mailComposerVC it is not a bad idea to check if you actually can send an email using
MFMailComposeViewController.canSendMail()
– Au Ris
May 2 '17 at 13:18
Before you create your mailComposerVC it is not a bad idea to check if you actually can send an email using
MFMailComposeViewController.canSendMail()
– Au Ris
May 2 '17 at 13:18
add a comment |
If you'd like to open the built-in email app as opposed to showing the MFMailComposeViewController
as has been mentioned by others, you could construct a mailto:
link like this:
let subject = "My subject"
let body = "The awesome body of my email."
let encodedParams = "subject=(subject)&body=(body)".stringByAddingPercentEncodingWithAllowedCharacters(.URLQueryAllowedCharacterSet())
let url = "mailto:foo@bar.com?(encodedParams)"
if let emailURL = NSURL(url) {
if UIApplication.sharedApplication().canOpenURL(emailURL) {
UIApplication.sharedApplication().openURL(emailURL)
}
}
Just to save anyone typing, for 2016 the syntax has changed slightly:
let subject = "Some subject"
let body = "Plenty of email body."
let coded = "mailto:blah@blah.com?subject=(subject)&body=(body)".stringByAddingPercentEncodingWithAllowedCharacters(.URLQueryAllowedCharacterSet())
if let emailURL:NSURL = NSURL(string: coded!)
{
if UIApplication.sharedApplication().canOpenURL(emailURL)
{
UIApplication.sharedApplication().openURL(emailURL)
}
the actual correct answer to the question on the page! thanks man! :)
– Fattie
Jul 27 '16 at 18:36
add a comment |
If you'd like to open the built-in email app as opposed to showing the MFMailComposeViewController
as has been mentioned by others, you could construct a mailto:
link like this:
let subject = "My subject"
let body = "The awesome body of my email."
let encodedParams = "subject=(subject)&body=(body)".stringByAddingPercentEncodingWithAllowedCharacters(.URLQueryAllowedCharacterSet())
let url = "mailto:foo@bar.com?(encodedParams)"
if let emailURL = NSURL(url) {
if UIApplication.sharedApplication().canOpenURL(emailURL) {
UIApplication.sharedApplication().openURL(emailURL)
}
}
Just to save anyone typing, for 2016 the syntax has changed slightly:
let subject = "Some subject"
let body = "Plenty of email body."
let coded = "mailto:blah@blah.com?subject=(subject)&body=(body)".stringByAddingPercentEncodingWithAllowedCharacters(.URLQueryAllowedCharacterSet())
if let emailURL:NSURL = NSURL(string: coded!)
{
if UIApplication.sharedApplication().canOpenURL(emailURL)
{
UIApplication.sharedApplication().openURL(emailURL)
}
the actual correct answer to the question on the page! thanks man! :)
– Fattie
Jul 27 '16 at 18:36
add a comment |
If you'd like to open the built-in email app as opposed to showing the MFMailComposeViewController
as has been mentioned by others, you could construct a mailto:
link like this:
let subject = "My subject"
let body = "The awesome body of my email."
let encodedParams = "subject=(subject)&body=(body)".stringByAddingPercentEncodingWithAllowedCharacters(.URLQueryAllowedCharacterSet())
let url = "mailto:foo@bar.com?(encodedParams)"
if let emailURL = NSURL(url) {
if UIApplication.sharedApplication().canOpenURL(emailURL) {
UIApplication.sharedApplication().openURL(emailURL)
}
}
Just to save anyone typing, for 2016 the syntax has changed slightly:
let subject = "Some subject"
let body = "Plenty of email body."
let coded = "mailto:blah@blah.com?subject=(subject)&body=(body)".stringByAddingPercentEncodingWithAllowedCharacters(.URLQueryAllowedCharacterSet())
if let emailURL:NSURL = NSURL(string: coded!)
{
if UIApplication.sharedApplication().canOpenURL(emailURL)
{
UIApplication.sharedApplication().openURL(emailURL)
}
If you'd like to open the built-in email app as opposed to showing the MFMailComposeViewController
as has been mentioned by others, you could construct a mailto:
link like this:
let subject = "My subject"
let body = "The awesome body of my email."
let encodedParams = "subject=(subject)&body=(body)".stringByAddingPercentEncodingWithAllowedCharacters(.URLQueryAllowedCharacterSet())
let url = "mailto:foo@bar.com?(encodedParams)"
if let emailURL = NSURL(url) {
if UIApplication.sharedApplication().canOpenURL(emailURL) {
UIApplication.sharedApplication().openURL(emailURL)
}
}
Just to save anyone typing, for 2016 the syntax has changed slightly:
let subject = "Some subject"
let body = "Plenty of email body."
let coded = "mailto:blah@blah.com?subject=(subject)&body=(body)".stringByAddingPercentEncodingWithAllowedCharacters(.URLQueryAllowedCharacterSet())
if let emailURL:NSURL = NSURL(string: coded!)
{
if UIApplication.sharedApplication().canOpenURL(emailURL)
{
UIApplication.sharedApplication().openURL(emailURL)
}
edited Jul 27 '16 at 19:08
Fattie
20.2k31200439
20.2k31200439
answered Nov 13 '15 at 14:58
mclaughlinjmclaughlinj
4,64742537
4,64742537
the actual correct answer to the question on the page! thanks man! :)
– Fattie
Jul 27 '16 at 18:36
add a comment |
the actual correct answer to the question on the page! thanks man! :)
– Fattie
Jul 27 '16 at 18:36
the actual correct answer to the question on the page! thanks man! :)
– Fattie
Jul 27 '16 at 18:36
the actual correct answer to the question on the page! thanks man! :)
– Fattie
Jul 27 '16 at 18:36
add a comment |
Swift 3 Version
let subject = "Some subject"
let body = "Plenty of email body."
let coded = "mailto:blah@blah.com?subject=(subject)&body=(body)".addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)
if let emailURL: NSURL = NSURL(string: coded!) {
if UIApplication.shared.canOpenURL(emailURL as URL) {
UIApplication.shared.openURL(emailURL as URL)
}
}
add a comment |
Swift 3 Version
let subject = "Some subject"
let body = "Plenty of email body."
let coded = "mailto:blah@blah.com?subject=(subject)&body=(body)".addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)
if let emailURL: NSURL = NSURL(string: coded!) {
if UIApplication.shared.canOpenURL(emailURL as URL) {
UIApplication.shared.openURL(emailURL as URL)
}
}
add a comment |
Swift 3 Version
let subject = "Some subject"
let body = "Plenty of email body."
let coded = "mailto:blah@blah.com?subject=(subject)&body=(body)".addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)
if let emailURL: NSURL = NSURL(string: coded!) {
if UIApplication.shared.canOpenURL(emailURL as URL) {
UIApplication.shared.openURL(emailURL as URL)
}
}
Swift 3 Version
let subject = "Some subject"
let body = "Plenty of email body."
let coded = "mailto:blah@blah.com?subject=(subject)&body=(body)".addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)
if let emailURL: NSURL = NSURL(string: coded!) {
if UIApplication.shared.canOpenURL(emailURL as URL) {
UIApplication.shared.openURL(emailURL as URL)
}
}
edited Jan 24 '18 at 4:28
answered Nov 6 '16 at 2:15
Matthew BarkerMatthew Barker
371412
371412
add a comment |
add a comment |
Swift 4.0
let email = "feedback@company.com"
let subject = "subject"
let bodyText = "Please provide information that will help us to serve you better"
if MFMailComposeViewController.canSendMail() {
let mailComposerVC = MFMailComposeViewController()
mailComposerVC.mailComposeDelegate = self
mailComposerVC.setToRecipients([email])
mailComposerVC.setSubject(subject)
mailComposerVC.setMessageBody(bodyText, isHTML: true)
self.present(mailComposerVC, animated: true, completion: nil)
} else {
let coded = "mailto:(email)?subject=(subject)&body=(bodyText)".addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)
if let emailURL = URL(string: coded!)
{
if UIApplication.shared.canOpenURL(emailURL)
{
UIApplication.shared.open(emailURL, options: [:], completionHandler: { (result) in
if !result {
// show some Toast or error alert
//("Your device is not currently configured to send mail.")
}
})
}
}
}
add a comment |
Swift 4.0
let email = "feedback@company.com"
let subject = "subject"
let bodyText = "Please provide information that will help us to serve you better"
if MFMailComposeViewController.canSendMail() {
let mailComposerVC = MFMailComposeViewController()
mailComposerVC.mailComposeDelegate = self
mailComposerVC.setToRecipients([email])
mailComposerVC.setSubject(subject)
mailComposerVC.setMessageBody(bodyText, isHTML: true)
self.present(mailComposerVC, animated: true, completion: nil)
} else {
let coded = "mailto:(email)?subject=(subject)&body=(bodyText)".addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)
if let emailURL = URL(string: coded!)
{
if UIApplication.shared.canOpenURL(emailURL)
{
UIApplication.shared.open(emailURL, options: [:], completionHandler: { (result) in
if !result {
// show some Toast or error alert
//("Your device is not currently configured to send mail.")
}
})
}
}
}
add a comment |
Swift 4.0
let email = "feedback@company.com"
let subject = "subject"
let bodyText = "Please provide information that will help us to serve you better"
if MFMailComposeViewController.canSendMail() {
let mailComposerVC = MFMailComposeViewController()
mailComposerVC.mailComposeDelegate = self
mailComposerVC.setToRecipients([email])
mailComposerVC.setSubject(subject)
mailComposerVC.setMessageBody(bodyText, isHTML: true)
self.present(mailComposerVC, animated: true, completion: nil)
} else {
let coded = "mailto:(email)?subject=(subject)&body=(bodyText)".addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)
if let emailURL = URL(string: coded!)
{
if UIApplication.shared.canOpenURL(emailURL)
{
UIApplication.shared.open(emailURL, options: [:], completionHandler: { (result) in
if !result {
// show some Toast or error alert
//("Your device is not currently configured to send mail.")
}
})
}
}
}
Swift 4.0
let email = "feedback@company.com"
let subject = "subject"
let bodyText = "Please provide information that will help us to serve you better"
if MFMailComposeViewController.canSendMail() {
let mailComposerVC = MFMailComposeViewController()
mailComposerVC.mailComposeDelegate = self
mailComposerVC.setToRecipients([email])
mailComposerVC.setSubject(subject)
mailComposerVC.setMessageBody(bodyText, isHTML: true)
self.present(mailComposerVC, animated: true, completion: nil)
} else {
let coded = "mailto:(email)?subject=(subject)&body=(bodyText)".addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)
if let emailURL = URL(string: coded!)
{
if UIApplication.shared.canOpenURL(emailURL)
{
UIApplication.shared.open(emailURL, options: [:], completionHandler: { (result) in
if !result {
// show some Toast or error alert
//("Your device is not currently configured to send mail.")
}
})
}
}
}
answered Jan 24 '18 at 13:04
Manish NaharManish Nahar
294312
294312
add a comment |
add a comment |
Use the MFMailComposeViewController
like this:
Import the MessageUI
import MessageUI
Add the delegate to your class:
class myClass: UIViewController, MFMailComposeViewControllerDelegate {}
Configure the email preset you want to have
let mail = MFMailComposeViewController()
mail.mailComposeDelegate = self
mail.setSubject("Subject")
mail.setMessageBody("Body", isHTML: true)
mail.setToRecipients(["my@email.com"])
presentViewController(mail, animated: true, completion: nil)
Put this method in your code:
func mailComposeController(controller: MFMailComposeViewController!, didFinishWithResult result: MFMailComposeResult, error: NSError!) {
dismissViewControllerAnimated(true, completion: nil)
}
There you go, works now.
2
do not forget check: if MFMailComposeViewController.canSendMail() {...
– djdance
Jan 5 '16 at 18:24
add a comment |
Use the MFMailComposeViewController
like this:
Import the MessageUI
import MessageUI
Add the delegate to your class:
class myClass: UIViewController, MFMailComposeViewControllerDelegate {}
Configure the email preset you want to have
let mail = MFMailComposeViewController()
mail.mailComposeDelegate = self
mail.setSubject("Subject")
mail.setMessageBody("Body", isHTML: true)
mail.setToRecipients(["my@email.com"])
presentViewController(mail, animated: true, completion: nil)
Put this method in your code:
func mailComposeController(controller: MFMailComposeViewController!, didFinishWithResult result: MFMailComposeResult, error: NSError!) {
dismissViewControllerAnimated(true, completion: nil)
}
There you go, works now.
2
do not forget check: if MFMailComposeViewController.canSendMail() {...
– djdance
Jan 5 '16 at 18:24
add a comment |
Use the MFMailComposeViewController
like this:
Import the MessageUI
import MessageUI
Add the delegate to your class:
class myClass: UIViewController, MFMailComposeViewControllerDelegate {}
Configure the email preset you want to have
let mail = MFMailComposeViewController()
mail.mailComposeDelegate = self
mail.setSubject("Subject")
mail.setMessageBody("Body", isHTML: true)
mail.setToRecipients(["my@email.com"])
presentViewController(mail, animated: true, completion: nil)
Put this method in your code:
func mailComposeController(controller: MFMailComposeViewController!, didFinishWithResult result: MFMailComposeResult, error: NSError!) {
dismissViewControllerAnimated(true, completion: nil)
}
There you go, works now.
Use the MFMailComposeViewController
like this:
Import the MessageUI
import MessageUI
Add the delegate to your class:
class myClass: UIViewController, MFMailComposeViewControllerDelegate {}
Configure the email preset you want to have
let mail = MFMailComposeViewController()
mail.mailComposeDelegate = self
mail.setSubject("Subject")
mail.setMessageBody("Body", isHTML: true)
mail.setToRecipients(["my@email.com"])
presentViewController(mail, animated: true, completion: nil)
Put this method in your code:
func mailComposeController(controller: MFMailComposeViewController!, didFinishWithResult result: MFMailComposeResult, error: NSError!) {
dismissViewControllerAnimated(true, completion: nil)
}
There you go, works now.
answered Nov 13 '15 at 14:27
LinusGeffarthLinusGeffarth
8,631145298
8,631145298
2
do not forget check: if MFMailComposeViewController.canSendMail() {...
– djdance
Jan 5 '16 at 18:24
add a comment |
2
do not forget check: if MFMailComposeViewController.canSendMail() {...
– djdance
Jan 5 '16 at 18:24
2
2
do not forget check: if MFMailComposeViewController.canSendMail() {...
– djdance
Jan 5 '16 at 18:24
do not forget check: if MFMailComposeViewController.canSendMail() {...
– djdance
Jan 5 '16 at 18:24
add a comment |
I suggest to use Apple's way, which you can find in official documentation about MFMailComposeViewController. It opens a modal view controller with the email, which is dismissed after sending. Thus user stays in your app.
1
OP asked for Swift code, your reference displays Obj-C instead.
– LinusGeffarth
Nov 13 '15 at 14:57
1
The link leads to Apple's documentation, where are all information, which could Jan possibly need, not only specific parts (methods/properties). Apple has the sample code only in ObjC in this case, but it could be easily translated to Swift.
– David Rysanek
Nov 14 '15 at 10:14
add a comment |
I suggest to use Apple's way, which you can find in official documentation about MFMailComposeViewController. It opens a modal view controller with the email, which is dismissed after sending. Thus user stays in your app.
1
OP asked for Swift code, your reference displays Obj-C instead.
– LinusGeffarth
Nov 13 '15 at 14:57
1
The link leads to Apple's documentation, where are all information, which could Jan possibly need, not only specific parts (methods/properties). Apple has the sample code only in ObjC in this case, but it could be easily translated to Swift.
– David Rysanek
Nov 14 '15 at 10:14
add a comment |
I suggest to use Apple's way, which you can find in official documentation about MFMailComposeViewController. It opens a modal view controller with the email, which is dismissed after sending. Thus user stays in your app.
I suggest to use Apple's way, which you can find in official documentation about MFMailComposeViewController. It opens a modal view controller with the email, which is dismissed after sending. Thus user stays in your app.
answered Nov 13 '15 at 14:28
David RysanekDavid Rysanek
656911
656911
1
OP asked for Swift code, your reference displays Obj-C instead.
– LinusGeffarth
Nov 13 '15 at 14:57
1
The link leads to Apple's documentation, where are all information, which could Jan possibly need, not only specific parts (methods/properties). Apple has the sample code only in ObjC in this case, but it could be easily translated to Swift.
– David Rysanek
Nov 14 '15 at 10:14
add a comment |
1
OP asked for Swift code, your reference displays Obj-C instead.
– LinusGeffarth
Nov 13 '15 at 14:57
1
The link leads to Apple's documentation, where are all information, which could Jan possibly need, not only specific parts (methods/properties). Apple has the sample code only in ObjC in this case, but it could be easily translated to Swift.
– David Rysanek
Nov 14 '15 at 10:14
1
1
OP asked for Swift code, your reference displays Obj-C instead.
– LinusGeffarth
Nov 13 '15 at 14:57
OP asked for Swift code, your reference displays Obj-C instead.
– LinusGeffarth
Nov 13 '15 at 14:57
1
1
The link leads to Apple's documentation, where are all information, which could Jan possibly need, not only specific parts (methods/properties). Apple has the sample code only in ObjC in this case, but it could be easily translated to Swift.
– David Rysanek
Nov 14 '15 at 10:14
The link leads to Apple's documentation, where are all information, which could Jan possibly need, not only specific parts (methods/properties). Apple has the sample code only in ObjC in this case, but it could be easily translated to Swift.
– David Rysanek
Nov 14 '15 at 10:14
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f33694771%2fopen-email-from-app-with-predefined-text-in-ios%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Do some research on the
mailto:
URL scheme. You can provide "to" addresses, "cc" addresses, a subject, and the message body. But of course the best option is to do what the answers below suggest.– rmaddy
Nov 13 '15 at 14:53