-
Notifications
You must be signed in to change notification settings - Fork 584
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #164 from sendgrid/apikeys-2
Implement pull #127, add api key constructors
- Loading branch information
Showing
7 changed files
with
255 additions
and
238 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,17 +61,8 @@ After creating an email message, you can send it using the Web API provided by S | |
|
||
Sending email requires that you supply your SendGrid account credentials (username and password) OR a SendGrid API Key. API Key is the preferred method. API Keys are in beta. To configure API keys, visit https://sendgrid.com/beta/settings/api_keys | ||
|
||
Using Credentials | ||
```csharp | ||
// Create network credentials to access your SendGrid account. | ||
var username = "your_sendgrid_username"; | ||
var pswd = "your_sendgrid_password"; | ||
|
||
var credentials = new NetworkCredential(username, pswd); | ||
``` | ||
To send an email message, use the **DeliverAsync** method on the **Web** transport class, which calls the SendGrid Web API. The following example shows how to send a message. | ||
|
||
|
||
```csharp | ||
// Create the email object first, then add the properties. | ||
SendGridMessage myMessage = new SendGridMessage(); | ||
|
@@ -80,18 +71,12 @@ myMessage.From = new MailAddress("[email protected]", "John Smith"); | |
myMessage.Subject = "Testing the SendGrid Library"; | ||
myMessage.Text = "Hello World!"; | ||
|
||
// Create credentials, specifying your user name and password. | ||
var credentials = new NetworkCredential("username", "password"); | ||
|
||
// Create an Web transport for sending email, using credentials... | ||
//var transportWeb = new Web(credentials); | ||
// ...OR create a Web transport, using API Key (preferred) | ||
var transportWeb = new Web("This string is an API key"); | ||
// Create a Web transport, using API Key | ||
var transportWeb = new Web("This string is a SendGrid API key"); | ||
|
||
// Send the email. | ||
transportWeb.DeliverAsync(myMessage); | ||
// If your developing a Console Application, use the following | ||
// NOTE: If your developing a Console Application, use the following so that the API call has time to complete | ||
// transportWeb.DeliverAsync(myMessage).Wait(); | ||
``` | ||
|
||
|
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
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
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
Oops, something went wrong.