Skip to content

Instantly share code, notes, and snippets.

@elbuo8
Created April 7, 2014 16:34
Show Gist options
  • Save elbuo8/10023719 to your computer and use it in GitHub Desktop.
Save elbuo8/10023719 to your computer and use it in GitHub Desktop.
ti.sendgrid blog
var sendgrid = require('tisendgrid')('SENDGRID-USERNAME', 'SENDGRID-PASSOWORD');
sendgrid.send({
to: '[email protected]',
from: '[email protected]',
subject: 'Hello!',
text: 'Hello again!'
}, function (e) {
if (e) {
console.log(e); // Email wasn't sent
}
});
var sendgrid = require('tisendgrid')('SENDGRID-USERNAME', 'SENDGRID-PASSOWORD');
var email = sendgrid.Email({
to: '[email protected]',
from: '[email protected]',
subject: 'Welcome!',
text: 'This is inside of the template!'
});
email.addFilter('template', 'enable', 1);
email.addFilter('template', 'text/html',
'<html><body>General template stuff.<% body %></body></html>');
sendgrid.send(email, function (e) {
if (e) {
console.log('Oups :( : ' + e);
}
});
@Jephta
Copy link

Jephta commented Jul 1, 2015

Hi there, this looks like a straight forward api but it is failing for me. i signed up for sendgrid account. i get error message at the end of calling the send function of tisendgrid library on Apcelerator Titanium Studio both on xampp and ipage hosted account. i don't know what i am doing wrong, please help, thanks, Jephta.

@Jephta
Copy link

Jephta commented Jul 1, 2015

I am developing an app with Titanium Studio, build: 3.4.1.201410281727 where users need to signup and am trying to use sendgrid to send emails to users but without success. I have signed up at sendgrid and have a userid and password that I am using at the xxxxxxx below. I am testing this with xampp locally and with ipage hosted account. The code runs up to where it says "Message Sent" and then gives an error as follows. "Application Error Uncaught Syntax Error: Unexpected end of input at line / (Line 1)"
Please see if you can help me out.

Thank you in advance.
Jephta.

Here is the code i am using:

var api_user = "xxxxxxxx";
var api_key = "xxxxxxxx"
var fromEmail = "[email protected]";
var theSubject = "Hello";
var theBody = "Hello from Jephta";

var sendgrid = require("tisendgrid")(api_user, api_key);

var email = {
to: emailAddress.value,
from: fromEmail,
subject: theSubject,
text: theBody
};

var message = sendgrid.Email(email);

sendgrid.send(message, function(e) {
if (e) {
alert(e.errors[0]);
} else {
alert("Message sent");
}
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment