A SendGrid CommonJS module for Titanium
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
app
plugins/ti.alloy
.gitignore
LICENSE
Makefile
README.md
tiapp.xml

README.md

IMPORTANT ANNOUNCEMENT

As of May 1, 2016, SendGrid will no longer support this library.

Please direct any questions to the Developer Experience team.

Titanium SendGrid

A SendGrid CommonJS library for Titanium

Simple CommonJS library to be used in Titanium projects in order to send emails through SendGrid's Web API.

Installation

Titanium IDE:

  • Copy tisendgrid.js into your lib folder.

Gittio:

  • TODO

Example

var sendgrid = require('tisendgrid')('SENDGRID-USERNAME', 'SENDGRID-PASSOWORD');
sendgrid.send({
	to: 'john@email.com',
	from: 'doe@email.com',
	subject: 'Hello!',
	text: 'Hello again!'
}, function (e) {
	if (e) {
		console.log(e); // Email wasn't sent
	}
});

Create Email Object

var sendgrid = require('tisendgrid')('SENDGRID-USERNAME', 'SENDGRID-PASSOWORD');
var email = sendgrid.Email({to: ['john@email', 'doe@email.com']});
var otherEmail = sendgrid.Email();

Adding Recipients

email.addTo('jose@email.com');
email.addTo(['jose2@email.com', 'happy@email.com']);

Adding ToName

email.addToName('Jose');
email.addToName(['Jose 2', 'Happy']);

Setting From

email.setFrom('joseph@email.com');

Setting FromName

email.setFromName('Joseph');

Setting Subject

email.setSubject('subject');

Setting Text

email.setText('this text');

Setting HTML

email.setHTML('<b>that html</b>');

Adding BCC Recipients

email.addBcc('jose@email.com');
email.addBcc(['jose2@email.com', 'happy@email.com']);

Setting Reply To

email.setReplyTo('email@email.com');

Setting Date

email.setDate(new Date().toUTCString());

Adding Files

// Filename parameter is optional
email.addFile('./filepath/file', 'filename');
email.addFile(file); // Titanium.Filesystem.File

Setting Header

email.setHeader('some header');

Setting SMTPAPI Header

email.setAPIHeader('{sub:{key:value}}');

SendGrid's X-SMTPAPI

Substitution

email.addSubstitution('key', 'value')

Section

email.addSection('section', 'value')

Category

email.addCategory('category')

Unique Arguments

email.addUniqueArg('key', 'value')

Filter

email.addFilter('filter', 'setting', 'value')

MIT License

Notes

Thanks to Ricardo Alcocer for the initial work! Pull requests are more than welcomed!