Coder Social home page Coder Social logo

android-sendgrid's Introduction

header

android-sendgrid

A simplified Android email library utilising SendGrid's v3 API that targets minSdkVersion 16.

Use with JitPack and implement in your app

allprojects {
    repositories {
        ...
        maven { url "https://jitpack.io" }
    }
}

dependencies {
     implementation 'com.github.jakebreen:android-sendgrid:1.3.1'
}

How to use

Create an instance of the SendGrid library tied to your API key.

SendGrid sendGrid = SendGrid.create(@NonNull String apiKey)

Create a SendGridMail and provide the required attributes.

SendGridMail mail = new SendGridMail()
mail.addRecipient(@NonNull String email, @Nullable String name)
mail.setFrom(@NonNull String email, @Nullable String name)
mail.setSubject(@NonNull String subject)
mail.setContent(@NonNull String body)

Set a plain text or a html text content body, when using a template neither of these content variables need to be set.

mail.setContent(@NonNull String body)
mail.setHtmlContent(@NonNull String body)

Send a mail with the library's SendTask.

SendTask task = new SendTask(sendGrid);
SendGridResponse response = task.send(mail);

Send a mail with RxJava.

Single.fromCallable(sendGrid.send(mail))
    .subscribeOn(Schedulers.io())
    .subscribe(response -> {
            if (response.isSuccessful()) {
                // ...
            }
        }
    );

Send requests return a SendGridResponse that contains the success state of the request and the associated HTTP response code. A failed request will contain the error message from the API.

response.isSuccessful()
response.getCode()
response.getErrorMessage()

Additional SendGridMail methods that aren't required to send an email include templates, tracking, carbon copies, attachments and others

mail.addAttachment(@NonNull File file)
mail.addAttachment(@NonNull Uri uri)
mail.addRecipientCarbonCopy(@NonNull String email, @Nullable String name)
mail.addRecipientBlindCarbonCopy(@NonNull String email, @Nullable String name)
mail.setReplyTo(@NonNull String email, @Nullable String name)
mail.setSendAt(@NonNull int sendAt)
mail.setClickTrackingEnabled(@NonNull Boolean enabled)
mail.setOpenTrackingEnabled(@NonNull Boolean enabled)
mail.setSubscriptionTrackingEnabled(@NonNull Boolean enabled)
mail.setUnsubscribeGroupId(@NonNull int groupId)
mail.setUnsubscribeGroupIds(@NonNull int groupId, List<Integer> groupIds)

Transactional email templates and custom data can be applied to the SendGridMail in the form of a JSONObject structured into key/value pairs

mail.setTemplateId(@NonNull String templateId)
mail.setDynamicTemplateData(@NonNull JSONObject jsonObject)

// JSONObject structured into key/value pairs
final JSONObject templateData = new JSONObject();
templateData.put("forename", "Jane");
templateData.put("surname", "Doe");
templateData.put("message", "Hello, This is my email");

mail.setDynamicTemplateData(templateData)

TestApp

A test app included when cloning the library to test the library with file attachments, uses RxJava2. Feel free utilise this app.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.