diff options
Diffstat (limited to 'SendGrid/Example')
-rwxr-xr-x | SendGrid/Example/Example.csproj | 1 | ||||
-rwxr-xr-x | SendGrid/Example/Program.cs | 21 | ||||
-rwxr-xr-x | SendGrid/Example/RESTAPI.cs | 78 | ||||
-rwxr-xr-x | SendGrid/Example/SMTPAPI.cs | 59 |
4 files changed, 149 insertions, 10 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/Program.cs b/SendGrid/Example/Program.cs index 3bbc1db..4d16952 100755 --- a/SendGrid/Example/Program.cs +++ b/SendGrid/Example/Program.cs @@ -18,11 +18,23 @@ namespace Example var from = "cj.buchmann@sendgrid.com";
var to = new List<String>
{
- "cj.buchmann@gmail.com"
+ "cj.buchmann@sendgrid.com",
+ "tyler.bischel@sendgrid.com"
};
+ var bcc = new List<string>
+ {
+ "eric@sendgrid.com"
+ };
+
+ var cc = new List<string>
+ {
+ "eric@sendgrid.com"
+ };
+
//initialize the SMTPAPI example class
var smtpapi = new SMTPAPI(username, password, from, to);
+ var restpapi = new RESTAPI(username, password, from, to, null, cc);
//send a simple HTML encoded email.
//smtpapi.SimpleHTMLEmail();
@@ -31,7 +43,12 @@ namespace Example //smtpapi.SimplePlaintextEmail();
//send a gravatar enabled email.
- smtpapi.EnableGravatarEmail();
+ //smtpapi.EnableGravatarEmail();
+
+ //send an open tracking enabled email.
+ //smtpapi.EnableOpenTrackingEmail();
+
+ restpapi.SimpleHTMLEmail();
}
}
}
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);
}
|