Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending Email With Swift [closed]

how would you send an email with swift in an app. Like say for example your user want's to reset their password in a social media application with Parse(or not), but you don't wan't to use MessageUI because you want it to be automatic. I've done some research and found out that it can be possible with mailgun but i cannot figure out how to use it with swift and XCode 6. Can you please help me?

like image 744
Noah Barsky Avatar asked Mar 10 '15 12:03

Noah Barsky


People also ask

What is a swift email?

Swift Mailer is a component based library for sending e-mails from PHP applications.

Why can't I send outgoing mail from my Iphone?

Contact your email provider or system administrator You might need a special password or might need to request authorization from your email provider to send and receive email on your device. Check your email account settings with your email provider or system administrator to make sure that they're correct.

Why are my emails stuck in outbox Iphone?

Messages may be stuck in outbox because the attachment size was too big, internet connectivity issues or there might be a problem with the account. When emails are in the outbox it may not allow you to send new emails and you will need to empty the outbox. Go to the Outbox any time there's a pending email in it.


2 Answers

Sure you can.

import Foundation import UIKit import MessageUI  class 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(["[email protected]"])         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

like image 85
Nurdin Avatar answered Oct 05 '22 02:10

Nurdin


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 protected]",   from: "[email protected]",   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");   } }); 
like image 40
picciano Avatar answered Oct 05 '22 01:10

picciano