summaryrefslogtreecommitdiffstats
path: root/SendGrid/Example/Program.cs
diff options
context:
space:
mode:
authorBrandon West <brawest@gmail.com>2014-10-09 15:52:10 -0600
committerBrandon West <brawest@gmail.com>2014-10-09 15:52:10 -0600
commit88bbde7219098f8699dfa971e6c88a879e01c3fb (patch)
tree38ad6fd56c28b405f65eae1f59dd29a1573b2b70 /SendGrid/Example/Program.cs
parentfc46788ff6da5e31559e0550607db735ecde4c2d (diff)
downloadsendgrid-csharp-88bbde7219098f8699dfa971e6c88a879e01c3fb.zip
sendgrid-csharp-88bbde7219098f8699dfa971e6c88a879e01c3fb.tar.gz
sendgrid-csharp-88bbde7219098f8699dfa971e6c88a879e01c3fb.tar.bz2
async exception handling example
Diffstat (limited to 'SendGrid/Example/Program.cs')
-rw-r--r--SendGrid/Example/Program.cs31
1 files changed, 21 insertions, 10 deletions
diff --git a/SendGrid/Example/Program.cs b/SendGrid/Example/Program.cs
index 9da69f5..fa97707 100644
--- a/SendGrid/Example/Program.cs
+++ b/SendGrid/Example/Program.cs
@@ -17,18 +17,29 @@ namespace Example
myMessage.Subject = "Testing the SendGrid Library";
myMessage.Text = "Hello World!";
- // Create credentials, specifying your user name and password.
- var credentials = new NetworkCredential("username", "password");
+ SendAsync(myMessage);
- // Create a Web transport for sending email.
- var transportWeb = new Web(credentials);
-
- // Send the email.
- if (transportWeb != null)
- transportWeb.DeliverAsync(myMessage);
-
- Console.WriteLine("Done!");
Console.ReadLine();
}
+
+ private static async void SendAsync(SendGridMessage message)
+ {
+ // Create credentials, specifying your user name and password.
+ var credentials = new NetworkCredential("username", "password");
+
+ // Create a Web transport for sending email.
+ var transportWeb = new Web(credentials);
+
+ // Send the email.
+ try
+ {
+ await transportWeb.DeliverAsync(message);
+ Console.WriteLine("Sent!");
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine(ex.Message);
+ }
+ }
}
} \ No newline at end of file