Created
April 19, 2015 01:17
-
-
Save jamessdixon/989720e694df8b560304 to your computer and use it in GitHub Desktop.
Send Grid Email in F#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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