Skip to content

Instantly share code, notes, and snippets.

@brandonmwest
brandonmwest / create template
Last active August 29, 2015 14:01
SendGrid web api v3 curl example
curl -X POST -d '{"name":"example_name"}' -H "Content-Type: application/json" -u sendgrid_username https://api.sendgrid.com/v3/templates
@brandonmwest
brandonmwest / no_tables.rb
Last active August 29, 2015 14:03
Convert tables to {% parameters %} liquid blocks
require 'rubygems'
require 'json'
require 'nokogiri'
require 'nokogiri-pretty'
require 'iconv'
require 'fileutils'
html_files = File.join("/Users/brandonwest/SendGrid/docs/source/API_Reference", "**", "*.{md,html}")
Dir.glob html_files do |html_file|
@brandonmwest
brandonmwest / webhook.rb
Last active August 29, 2015 14:15
Log a JSON payload in Sinatra
post '/event' do
status 204 #successful request with no body content
request.body.rewind
request_payload = JSON.parse(request.body.read)
#append the payload to a file
File.open("events.txt", "a") do |f|
f.puts(request_payload)
end
{
"email"=>"john.doe@sendgrid.com",
"sg_event_id"=>"VzcPxPv7SdWvUugt-xKymw",
"sg_message_id"=>"142d9f3f351.7618.254f56.filter-147.22649.52A663508.0",
"timestamp"=>1386636112, "smtp-id"=>"<142d9f3f351.7618.254f56@sendgrid.com>",
"event"=>"processed",
"category"=>["category1", "category2", "category3"],
"id"=>"001",
"purchase"=>"PO1452297845",
"uid"=>"123456"
@brandonmwest
brandonmwest / testing.php
Created February 28, 2012 16:23
Testing WP integration
<?php
include_once "lib/swift_required.php";
/*
* Create the body of the message (a plain-text and an HTML version).
* $text is your plain-text email
* $html is your html version of the email
* If the reciever is able to view html emails then only the html
* email will be displayed
@brandonmwest
brandonmwest / gist:3384117
Created August 18, 2012 03:17
Adding recipients to the X-SMTPAPI Header with sendgrid-csharp
using System;
using System.Collections.Generic;
using SendGridMail;
using System.Net;
using SendGridMail.Transport;
using System.Net.Mail;
namespace EmailTester
{
class MainClass
@brandonmwest
brandonmwest / fake_names.rb
Created September 5, 2012 02:35
Generate a csv of fake names and email addresses
require 'faker'
require 'csv'
CSV.open("output.csv", "wb") do |csv|
i=0
until i == 25000
fake = [Faker::Name.name, Faker::Internet.email]
csv << fake
i=i+1
end
@brandonmwest
brandonmwest / gist:4559791
Last active December 11, 2015 06:29
Windows Azure + SendGrid example

#How to: Create an email

Use the static SendGrid.GetInstance method to create an email message that is of type SendGrid. Once the message is created, you can use SendGrid properties and methods to set values including the email sender, the email recipient, and the subject and body of the email.

The following example demonstrates how to create an email object and populate it:

// Create the email object first, then add the properties.
var myMessage = SendGrid.GetInstance();
@brandonmwest
brandonmwest / prettyprint.rb
Created February 24, 2013 01:07
Jekyll filter for pretty-printing HTML
require 'rubygems'
require 'json'
require 'nokogiri'
require 'nokogiri-pretty'
require 'fileutils'
module Jekyll
module PrettyPrintFilter
def pretty_print(input)
#seeing some ASCII-8 come in
@brandonmwest
brandonmwest / gist:5663960
Created May 28, 2013 16:16
sendgrid-perl example
use warnings;
use strict;
use Mail::SendGrid;
use Mail::SendGrid::Transport::SMTP;
my $sg = Mail::SendGrid->new( from => 'from@example.com',
to => 'to@example.com',
subject => 'Testing',
text => "Some text http://sendgrid.com/\n",