SendGrid is an email service trusted by developers and marketers for time-savings, scalability and delivery expertise.
To get an overview of SendGrid features and functionality click here.
If any suggestions or addition of new methods create a pull request. For further support, comment or create issues on this repo.
This is an ipm package, which contains one or more reusable assets within the ipm Community. The 'package.json' in this repo is a ipm spec's package.json, here, which is a superset of npm's package.json spec, here.
- Create a free SendGrid Account.
- Log into your SendGrid account, and view the Settings > API Keys tab. Create an API Key with full access to "Mail Send" rights.
- Update
SendGridConstants
Library
// TODO Use your own credentials, these are examples
var SEND_GRID_TOKEN = "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"
var ORIGIN_EMAIL = "[email protected]";
var EMAIL_RECIPIENTS = ["[email protected]"]
- Add 'SendGridEmail' as a dependency to any of your code services (Settings > Requires > Add)
Run ExampleSendEmailPlaintext
Code Service, also here for reference:
var sgEmail = SendGridEmail(SEND_GRID_TOKEN, ORIGIN_EMAIL)
sgEmail.SendEmailToList("Alert!", "ClearBlade Email Alert", EMAIL_RECIPIENTS, function(err, data){
if(err){
resp.error(err)
}
var message = "Successful email sent!"
resp.success(message);
});
Examples:
ExampleSendEmailPlaintext
- Sends an email with static plaintext contentExampleSendEmailParameterized
- Sends an email with a dynamic plaintext content with parameter passed into Code ServiceExampleSendEmailHTML
- Sends an email with static HTML contentExampleSendEmailAdvanced
- Sends an email with dynamic HTML Content passed into Code Service
Tests:
TestSendEmailMissingAuthToken
- Tests init and validation logicTestSendEmailMissingOriginEmail
- Tests validation of origin email
SendGridConstants
- This lib has constants which needs to be set by the user to test the example services. It is recommended to store keys in the constants library for centralized management of keys.SendGridEmail
- Described in the API section.
- callback :
function
This callback is displayed as part of sgEmail.
- SendGridEmail :
Object
Email service trusted by developers and marketers for time-savings, scalability, and delivery expertise.
This callback is displayed as part of sgEmail.
Kind: global typedef
Param | Type |
---|---|
err | Object |
resp | Object |
Email service trusted by developers and marketers for time-savings, scalability, and delivery expertise.
Kind: global typedef
Param | Type |
---|---|
authToken | string |
originEmail | string |
Example
var sgEmail = SendGridEmail(SEND_GRID_TOKEN, ORIGIN_EMAIL)
SendEmailToList = Sends email with given subject and body to a list of recipients.
Kind: static method of SendGridEmail
Returns: Object
- response, as specified in sendgrid api
Param | Type | Description |
---|---|---|
emailBody | string |
body of your email |
subject | string |
subject of your email |
recipientList | Array.<string> |
list of recipients |
callback | callback |
Example
//Assign relevant values to the variables and constants
var sgEmail = SendGridEmail(SEND_GRID_TOKEN, ORIGIN_EMAIL)
sgEmail.SendEmailToList(message, subject, emailRecipientList, function(err, data){
if(err){
resp.error(err)
}
var message = "Successful email sent!"
resp.success(message);
});