Skip to content

Instantly share code, notes, and snippets.

@jamessdixon
Created April 19, 2015 01:17
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jamessdixon/989720e694df8b560304 to your computer and use it in GitHub Desktop.
Save jamessdixon/989720e694df8b560304 to your computer and use it in GitHub Desktop.
Send Grid Email in F#
#r "~/packages/Sendgrid.5.1.0/lib/SendGridMail.dll"
#r "~/packages/SendGrid.SmtpApi.1.2.1/lib/net40/SendGrid.SmtpApi.dll"
open System
open System.Collections.Generic
open System.Net
open System.Net.Mail
open SendGrid
let message = new SendGridMessage()
message.From <- new MailAddress("snadella@microsoft.com")
let recipients = new List<string>()
recipients.Add("bgates@microsoft.com")
message.AddTo(recipients)
message.Subject <- "Testing the SendGrid Library"
message.Html <- "<p>Hello World!</p>"
message.Text <- "Hello world plain text!"
let username = "yourNameHere";
let pswd = "yourPasswordHere";
let credentials = new NetworkCredential(username, pswd);
let transportWeb = new Web(credentials);
try
let mailResult = transportWeb.Deliver(message);
()
with
| :? Exceptions.InvalidApiRequestException as ex -> ex.Errors |> Seq.iter( fun e -> printfn "Exception! %s " e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment