Sending Mail using MailGun in Google App Engine

Google App engine provides an email service to send email. Unfortunately it is limited to 100 emails per day. So we uses mailgun to send an email.

Let me share the code that we used in our Java project to send an email using mailgun.

  public static final String MAILGUN_API_KEY = "YOUR_MAILGUN_API_KEY";
  public static final String MAILGUN_HOST = "example.com"; // your host name

  public static void sendMail(String to, Set<String> cc, String subject,
      String html) {

    Client client = Client.create();
    client.addFilter(new HTTPBasicAuthFilter("api", MAILGUN_API_KEY));

    WebResource webResource = client.resource("https://api.mailgun.net/v2/"
        + MAILGUN_HOST + "/messages");

    MultivaluedMapImpl formData = new MultivaluedMapImpl();
    formData.add("from", "Example <hello@example.com>"); // your host email address
    formData.add("to", to);
    formData.add("subject", subject);
    formData.add("html", html);

    ClientResponse clientResponse = webResource.type(
        MediaType.APPLICATION_FORM_URLENCODED).post(
        ClientResponse.class, formData);
    int status = clientResponse.getStatus();
    if (status >= 400) {
      System.out.println(clientResponse.getEntity(String.class));
    }
  }

Have a nice day.

View comments

Social Sharing in Ionic application

You may need a social sharing feature inside your Ionic Framework Android and iOS application.

Using the Social Sharing plugin for Apache Cordova, we are able to do the social sharing.

Add ngCordova

First you have to add ngCordova to your Ionic application. If you already have this in your app, you can skip this step.

Install ngCordova

bower install ngCordova --save

Add ng-cordova.js before cordova script inside index.html

//index.html
<script src="lib/ngCordova/dist/ng-cordova.js"></script>
<script src="cordova.js"></script>

Add ngCordova in your app module dependencies

angular.module('myApp', ['ionic', 'ngCordova'])

Add Social Sharing cordova plugin

In order to implement social sharing, add cordova social sharing plugin.

cordova plugin add https://github.com/EddyVerbruggen/SocialSharing-PhoneGap-Plugin.git

Implement Social sharing

Now, go ahead and start creating method to share in your controllers

// share anywhere
$scope.share = function () {
    $cordovaSocialSharing.share('This is my message', 'Subject string', null, 'http://www.mylink.com');
}

// Share via email. Can be used for feedback
$scope.sendFeedback = function () {
    $cordovaSocialSharing
            .shareViaEmail('Some message', 'Some Subject', 'to_address@gmail.com');
}

// Share via SMS. Access multiple numbers in a string like: '0612345678,0687654321'
$scope.sendSMS = function (message, number) {
    $cordovaSocialSharing.shareViaSMS(message, number);
}

For more functionalities, refer the documentation.

Have a nice day.

View comments

Rate this app in Ionic application

You may need a "Rate this app" link inside your Ionic Framework Android and iOS application. When I implemented this features by adding the link to Google Play and App Store, the link does not work. Then I found that it needs inappbrowser cordova plugin.

Add InApp Browser cordova plugin

cordova plugin add org.apache.cordova.inappbrowser

Implement "Rate this app"

Now, go ahead and start creating method to open a link based on the device.

<button ng-click="rateUs()">Rate us</button>
$scope.rateUs = function () {
    if ($ionicPlatform.is('ios')) {
        window.open('itms-apps://itunes.apple.com/us/app/domainsicle-domain-name-search/id511364723?ls=1&mt=8'); // or itms://
    } else if ($ionicPlatform.is('android')) {
        window.open('market://details?id=<package_name>');
    }
}

Have a nice day.

View comments