Skip to content

Latest commit

 

History

History
183 lines (126 loc) · 3.83 KB

File metadata and controls

183 lines (126 loc) · 3.83 KB

SMTPAPI for Java

This module will let you build SendGrid's SMTP API headers with simplicity.

BuildStatus

Installing

Choose your installation method - Maven w/ Gradle (recommended) or Jar file.

Maven w/ Gradle

...
dependencies {
  ...
  compile 'com.sendgrid:smtpapi-java:1.2.0'
}

repositories {
  mavenCentral()
}
...

Then import the library - in the file appropriate to your Java project.

import com.sendgrid.smtpapi.SMTPAPI;

Jar file

You can just drop the jar file in. It's a fat jar - it has all the dependencies built in.

smtpapi-java.jar

Examples

Create headers

import com.sendgrid.smtpapi.SMTPAPI;
SMTPAPI header = new SMTPAPI();
header.addTo("email@email.com");
// or
header.addTo(["email@email.com"]);
// or
header.setTos(["email@email.com"]);

String[] tos = header.getTos();
header.addSubstitution("key", "value");

JSONObject subs = header.getSubstitutions();
header.addUniqueAarg("key", "value");
// or
Map map = new HashMap<String, String>();
map.put("unique", "value");
header.setUniqueArgs(map);
// or
JSONObject map = new JSONObject();
map.put("unique", "value");
header.setUniqueArgs(map);

JSONObject args = header.getUniqueArgs();
header.addCategory("category");
// or
header.addCategory(["categories"]);
// or
header.setCategories(["category1", "category2"]);

String[] cats = header.getCategories();
header.addSection("key", "section");
// or
Map newSec = new HashMap();
newSec.put("-section-", "value");
header.setSections(newSec);
// or
JSONObject newSec = new JSONObject();
newSec.put("-section-", "value");
header.setSections(newSec);

JSONObject sections = header.getSections();
header.addFilter("filter", "setting", "value");
header.addFilter("filter", "setting", 1);

JSONObject filters = header.getFilters();
header.setASMGroupId(1);

Integer groupId = header.getASMGroupId();
header.setSendAt(1416427645)

int sendAt = header.getSendAt();

Get Headers

String headers = header.jsonString();

If you need the unescaped JSON string.

String rawJson = header.rawJsonString();

Running Tests

./gradlew check

Publishing to Maven

This only works if you have the correct permissions - for admins only basically.

cp gradle.properties.example gradle.properties

Edit the contents of gradle.properties with your credentials.

./gradlew
./gradlew uploadArchives

Login to Sonatype.

Go to staging repositories page.

Click 'Close' with the archive selected.

Wait a few minutes, and refresh the staging repositories page.

Check the box for the SendGrid repo again and this time click 'Release'.

You're all done.

Further help.

MIT