ParseEmailtoPush is a demo application provided by Mailgun and Parse. It was written to demonstrate the capabilities of combining the Mailgun and Parse platform. The application will accept an email and convert the email to a Push Notification for mobile devices. iOS is used for demonstration purposes.
Note: This demo application assumes you understand Mailgun, Parse, and iOS programming. For beginners, be sure to follow the guides provided for each "module" on the various platforms.
Mailgun: http://www.mailgun.com
Parse: http://www.parse.com
Webcast Demo: http://blog.parse.com/2013/01/15/register-for-the-webcast-using-email-to-send-push-notifications-with-parse-and-mailgun/
Developed by: Travis Swientek, Mailgun, Inc.
Date: January 20, 2013
- User sends an email to a Mailgun "Route" via defined email address.
- Mailgun parses the email and posts the message to route endpoint (MG2Parse.php).
- MG2Parse.php parses the inbound POST and stores the received data in a Parse Class.
- The Parse Class, upon saving the inbound Object, uses "Cloud Code" to send a confirmation email to the sender.
- The confirmation email contains a validation link. The end user clicks the link to validate the Push Notification.
- MG2Parse.php is called to issue a Push Notification to the Parse REST API.
- The push notification is delivered to the mobile clients, for the defined channel.
Parse -
- Create a new Class titled "PushNotifications" (or whatever you want, define in MG2Parse.php).
- Add the following columns (keeping all default columns): channel (string), message (string), sender (string), sent (number).
Mailgun -
- Considering your account is already setup to receive email on a domain.
- Go to the Routes tab and add a new Route defined like "push+.@<yourdomain.com>". Example: push+.@parsedemo.com
- Set the route to point to the script "MG2Parse.php". Note: You must host this script on a server accessible from the internet.
Mailgun Example -
Filter Expression: match_recipient("push+.*@parsedemo.com")
Actions: forward("http://parsedemo.com/MG2Parse.php")
MG2Parse.php -
Note: Requires PHP version 5 or newer.
- Obtain your Mailgun API key, Parse Application ID, and Parse API Key.
- Add these values, within the constants, for the configuration section.
- Define valid "senders" to ensure spammers don't spam your endpoint.
- Disable security during testing, enable when you put in production.
Main.js -
- Open this file and add your domain and Mailgun API key.
- Make modifications as you see fit. (e.g. Adjust the From, Subject and Body fields)
- Deploy the script using Parse Cloud Code tools. https://parse.com/docs/cloud_code_guide
iOS App -
- Follow the "Quick Start" guidelines to add the Parse SDK to a new or existing app. https://parse.com/apps/quickstart?app_id=mailgun-test-app#ios/blank
- Configure your Parse account for iOS Push Notifications. https://parse.com/apps/quickstart_push
- Once your iOS app is configured for Parse and Push Notifications, subscribe yourself to any channel by issuing:
[PFPush subscribeToChannel:@"myawesomechannel" error:nil];
- Build and run the app on a physical iOS device, as the simulator cannot handle Push Notifications.
- Test by sending an email to your endpoint.
Mailgun Support: [email protected]
Parse Support: https://parse.com/help
Mailgun Documentation: http://documentation.mailgun.net/
Parse Documentation: https://parse.com/docs/
Contact Developer: Travis Swientek - [email protected]
MG2Parse is licensed under a Creative Commons Attribution 3.0 Unported License.
http://creativecommons.org/licenses/by/3.0/deed.en_US