summaryrefslogtreecommitdiffstats
path: root/SendGrid/Example
diff options
context:
space:
mode:
authorCJ Buchmann <cj.buchmann@sendgrid.com>2012-01-12 16:08:13 -0800
committerCJ Buchmann <cj.buchmann@sendgrid.com>2012-01-12 16:08:13 -0800
commit149f8c4ddb933f91fa32f6216d3fe78ae0636d0e (patch)
treed62ffae05d02608b811254f7ea708698b24e1363 /SendGrid/Example
parent5be7429848bf36f52381d2dff4001d009f5ee89e (diff)
downloadsendgrid-csharp-149f8c4ddb933f91fa32f6216d3fe78ae0636d0e.zip
sendgrid-csharp-149f8c4ddb933f91fa32f6216d3fe78ae0636d0e.tar.gz
sendgrid-csharp-149f8c4ddb933f91fa32f6216d3fe78ae0636d0e.tar.bz2
Added support for Rest API, to get mailing working. Also added examples to send a simple web api.
Diffstat (limited to 'SendGrid/Example')
-rwxr-xr-xSendGrid/Example/Example.csproj1
-rwxr-xr-xSendGrid/Example/RESTAPI.cs78
-rwxr-xr-xSendGrid/Example/SMTPAPI.cs59
3 files changed, 130 insertions, 8 deletions
diff --git a/SendGrid/Example/Example.csproj b/SendGrid/Example/Example.csproj
index b2558bd..776c740 100755
--- a/SendGrid/Example/Example.csproj
+++ b/SendGrid/Example/Example.csproj
@@ -47,6 +47,7 @@
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="RESTAPI.cs" />
<Compile Include="SMTPAPI.cs" />
</ItemGroup>
<ItemGroup>
diff --git a/SendGrid/Example/RESTAPI.cs b/SendGrid/Example/RESTAPI.cs
new file mode 100755
index 0000000..ca4e507
--- /dev/null
+++ b/SendGrid/Example/RESTAPI.cs
@@ -0,0 +1,78 @@
+using System;
+using System.Collections.Generic;
+using System.Net;
+using System.Net.Mail;
+using SendGridMail;
+using SendGridMail.Transport;
+
+namespace Example
+{
+ class RESTAPI
+ {
+ private String _username;
+ private String _password;
+ private String _from;
+ private IEnumerable<String> _to;
+ private IEnumerable<String> _bcc;
+ private IEnumerable<String> _cc;
+
+ public RESTAPI(String username, String password, String from, IEnumerable<String> recipients, IEnumerable<String> bcc, IEnumerable<String> cc)
+ {
+ _username = username;
+ _password = password;
+ _from = from;
+ _to = recipients;
+ _bcc = bcc;
+ _cc = cc;
+ }
+
+ public void SimpleHTMLEmail()
+ {
+ //create a new message object
+ var message = new SendGrid(new Header());
+
+ //set the message recipients
+
+ if(_to != null)
+ {
+ foreach (String recipient in _to)
+ {
+ message.AddTo(recipient);
+ }
+ }
+
+
+ if(_bcc != null)
+ {
+ foreach (String blindcc in _bcc)
+ {
+ message.AddBcc(blindcc);
+ }
+ }
+
+ if(_cc != null)
+ {
+ foreach (String cc in _cc)
+ {
+ message.AddCc(cc);
+ }
+ }
+
+
+ //set the sender
+ message.From = new MailAddress(_from);
+
+ //set the message body
+ message.Html = "<html><p>Hello</p><p>World</p></html>";
+
+ //set the message subject
+ message.Subject = "Hello World Simple Test";
+
+ //create an instance of the SMTP transport mechanism
+ var restInstance = new REST(new NetworkCredential(_username, _password));
+
+ //send the mail
+ restInstance.Deliver(message);
+ }
+ }
+}
diff --git a/SendGrid/Example/SMTPAPI.cs b/SendGrid/Example/SMTPAPI.cs
index f4a48db..6ed10cb 100755
--- a/SendGrid/Example/SMTPAPI.cs
+++ b/SendGrid/Example/SMTPAPI.cs
@@ -28,10 +28,13 @@ namespace Example
var message = new SendGrid(new Header());
//set the message recipients
- message.AddTo("cj.buchmann@sendgrid.com");
+ foreach(string recipient in _to)
+ {
+ message.AddTo(recipient);
+ }
//set the sender
- message.From = new MailAddress("eric@sendgrid.com");
+ message.From = new MailAddress(_from);
//set the message body
message.Html = "<html><p>Hello</p><p>World</p></html>";
@@ -52,10 +55,13 @@ namespace Example
var message = new SendGrid(new Header());
//set the message recipients
- message.AddTo("cj.buchmann@sendgrid.com");
+ foreach(string recipient in _to)
+ {
+ message.AddTo(recipient);
+ }
//set the sender
- message.From = new MailAddress("eric@sendgrid.com");
+ message.From = new MailAddress(_from);
//set the message body
message.Text = "Hello World Plain Text";
@@ -77,19 +83,22 @@ namespace Example
var message = new SendGrid(header);
//set the message recipients
- message.AddTo("cj.buchmann@sendgrid.com");
+ foreach (string recipient in _to)
+ {
+ message.AddTo(recipient);
+ }
//set the sender
- message.From = new MailAddress("cj.buchmann@sendgrid.com");
+ message.From = new MailAddress(_from);
//set the message body
- message.Html = "<p style='color:red';>Hello World Plain Text</p>";
+ message.Html = "<p style='color:red';>Hello World Gravatar Email</p>";
//set the message subject
message.Subject = "Hello World Simple Test";
//create an instance of the SMTP transport mechanism
- //var smtpInstance = SMTP.GenerateInstance(new NetworkCredential(_username, _password));
+ var smtpInstance = SMTP.GenerateInstance(new NetworkCredential(_username, _password));
//enable gravatar
message.EnableGravatar();
@@ -98,6 +107,40 @@ namespace Example
Console.WriteLine("done");
//send the mail
+ smtpInstance.Deliver(message);
+ }
+
+ public void EnableOpenTrackingEmail()
+ {
+ var header = new Header();
+ //create a new message object
+ var message = new SendGrid(header);
+
+ //set the message recipients
+ foreach (string recipient in _to)
+ {
+ message.AddTo(recipient);
+ }
+
+ //set the sender
+ message.From = new MailAddress(_from);
+
+ //set the message body
+ message.Html = "<p style='color:red';>Hello World Plain Text</p>";
+
+ //set the message subject
+ message.Subject = "Hello World Simple Test";
+
+ //create an instance of the SMTP transport mechanism
+ //var smtpInstance = SMTP.GenerateInstance(new NetworkCredential(_username, _password));
+
+ //enable gravatar
+ message.EnableOpenTracking();
+
+ Console.WriteLine(header.AsJson());
+
+ Console.WriteLine("done");
+ //send the mail
//smtpInstance.Deliver(message);
}