Skip to content

Instantly share code, notes, and snippets.

@lessismore1
Forked from jamessdixon/SendGridEmail
Created March 26, 2018 18:15
Show Gist options
  • Save lessismore1/4ef54cf525e8b752e0b8ad357ec2a542 to your computer and use it in GitHub Desktop.
Save lessismore1/4ef54cf525e8b752e0b8ad357ec2a542 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("[email protected]")
let recipients = new List<string>()
recipients.Add("[email protected]")
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