Sending Email With Swift [closed] Sending Email With Swift [closed] ios ios

Sending Email With Swift [closed]


Sure you can.

import Foundationimport UIKitimport MessageUIclass ViewController: ViewController,MFMailComposeViewControllerDelegate {    @IBAction func sendEmailButtonTapped(sender: AnyObject) {        let mailComposeViewController = configuredMailComposeViewController()        if MFMailComposeViewController.canSendMail() {            self.presentViewController(mailComposeViewController, animated: true, completion: nil)        } else {            self.showSendMailErrorAlert()        }    }    func configuredMailComposeViewController() -> MFMailComposeViewController {        let mailComposerVC = MFMailComposeViewController()        mailComposerVC.mailComposeDelegate = self // Extremely important to set the --mailComposeDelegate-- property, NOT the --delegate-- property        mailComposerVC.setToRecipients(["nurdin@gmail.com"])        mailComposerVC.setSubject("Sending you an in-app e-mail...")        mailComposerVC.setMessageBody("Sending e-mail in-app is not so bad!", isHTML: false)        return mailComposerVC    }    func showSendMailErrorAlert() {        let sendMailErrorAlert = UIAlertView(title: "Could Not Send Email", message: "Your device could not send e-mail.  Please check e-mail configuration and try again.", delegate: self, cancelButtonTitle: "OK")        sendMailErrorAlert.show()    }    // MARK: MFMailComposeViewControllerDelegate    func mailComposeController(controller: MFMailComposeViewController!, didFinishWithResult result: MFMailComposeResult, error: NSError!) {        controller.dismissViewControllerAnimated(true, completion: nil)    }}

Source Andrew Bancroft


Parse supports both Mailgun and Mandrill out of the box.See their documentation

You will need to write a CloudCode function, then call it from your app.

PFCloud.callFunctionInBackground("hello", withParameters:[:]) {  (result: AnyObject!, error: NSError!) -> Void in  if error == nil {    // result is "Hello world!"  }}

Example code snippets to send mail using Mailgun.

var Mailgun = require('mailgun');Mailgun.initialize('myDomainName', 'myAPIKey');Mailgun.sendEmail({  to: "email@example.com",  from: "Mailgun@CloudCode.com",  subject: "Hello from Cloud Code!",  text: "Using Parse and Mailgun is great!"}, {  success: function(httpResponse) {    console.log(httpResponse);    response.success("Email sent!");  },  error: function(httpResponse) {    console.error(httpResponse);    response.error("Uh oh, something went wrong");  }});