diff options
Diffstat (limited to 'SendGrid/Example')
-rwxr-xr-x | SendGrid/Example/Example.csproj | 16 | ||||
-rwxr-xr-x | SendGrid/Example/Program.cs | 65 | ||||
-rwxr-xr-x | SendGrid/Example/RESTAPI.cs | 95 | ||||
-rwxr-xr-x | SendGrid/Example/SMTPAPI.cs | 202 | ||||
-rwxr-xr-x | SendGrid/Example/app.config | 4 |
5 files changed, 380 insertions, 2 deletions
diff --git a/SendGrid/Example/Example.csproj b/SendGrid/Example/Example.csproj index 8ce66d2..cb778d1 100755 --- a/SendGrid/Example/Example.csproj +++ b/SendGrid/Example/Example.csproj @@ -11,7 +11,8 @@ <RootNamespace>Example</RootNamespace>
<AssemblyName>Example</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
- <TargetFrameworkProfile>Client</TargetFrameworkProfile>
+ <TargetFrameworkProfile>
+ </TargetFrameworkProfile>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
@@ -46,6 +47,19 @@ <ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="RESTAPI.cs" />
+ <Compile Include="SMTPAPI.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\SendGridMail\Mail.csproj">
+ <Project>{3C687BEF-FF50-44AD-8315-2D4237281AF8}</Project>
+ <Name>Mail</Name>
+ </ProjectReference>
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config">
+ <SubType>Designer</SubType>
+ </None>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
diff --git a/SendGrid/Example/Program.cs b/SendGrid/Example/Program.cs index abf67f0..87c44a4 100755 --- a/SendGrid/Example/Program.cs +++ b/SendGrid/Example/Program.cs @@ -1,16 +1,79 @@ using System;
using System.Collections.Generic;
using System.Linq;
+using System.Net;
using System.Net.Mail;
using System.Text;
+using SendGridMail;
+using SendGridMail.Transport;
namespace Example
{
class Program
{
- static void Main(string[] args)
+ static void Main(String[] args)
{
+ var restInstance = REST.GetInstance(new NetworkCredential("sgrid_username", "sgrid_password"));
+ //create a new message object
+ var message = SendGrid.GenerateInstance();
+
+ message.AddTo("cj.buchmann@sendgrid.com");
+ message.AddTo("tyler.bischel@sendgrid.com");
+ message.AddTo("kyle.partridge@sendgrid.com");
+ message.From = new MailAddress("cj.buchmann@sendgrid.com");
+ message.Html = "<div>hello world</div>";
+ message.Subject = "Hello World SUbject";
+ message.AddAttachment(@"C:\Users\Public\Pictures\Sample Pictures\Koala.jpg");
+ message.AddAttachment(@"C:\Users\Public\Pictures\Sample Pictures\Jellyfish.jpg");
+
+ restInstance.Deliver(message);
+
+ Console.WriteLine("Message Sent");
+ Console.WriteLine("DONE!");
+ Console.ReadLine();
}
+
+ // this code is used for the SMTPAPI examples
+ /*static void Main(string[] args)
+ {
+ var username = "cjbuchmann";
+ var password = "gadget15";
+ var from = "cj.buchmann@sendgrid.com";
+ var to = new List<String>
+ {
+ "cj.buchmann@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);
+
+ //send a simple HTML encoded email.
+ //smtpapi.SimpleHTMLEmail();
+
+ //send a simple Plaintext email.
+ //smtpapi.SimplePlaintextEmail();
+
+ //send a gravatar enabled email.
+ //smtpapi.EnableGravatarEmail();
+
+ //send an open tracking enabled email.
+ //smtpapi.EnableOpenTrackingEmail();
+
+ //send an open tracking enabled email.
+ smtpapi.EnableClickTrackingEmail();
+
+ Console.ReadLine();
+ }*/
}
}
diff --git a/SendGrid/Example/RESTAPI.cs b/SendGrid/Example/RESTAPI.cs new file mode 100755 index 0000000..73dbf04 --- /dev/null +++ b/SendGrid/Example/RESTAPI.cs @@ -0,0 +1,95 @@ +using System;
+using System.Linq;
+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 = SendGrid.GenerateInstance();
+
+ //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);
+ }
+ }
+
+ var headers = new Dictionary<String, String>
+ {
+ {"key1", "value1"},
+ {"key2", "value2"},
+ {"icanhazcheeze", "kthnxbye"}
+ };
+
+ message.AddHeaders(headers);
+
+ //var replyTo = new List<MailAddress> { new MailAddress("tyler.bischel@sendgrid.com") };
+
+ //message.ReplyTo = replyTo.ToArray();
+
+ //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";
+
+ message.AddAttachment(@"D:\att_proj\21.jpg");
+
+ //Utils.PrepareAttachments();
+
+ //create an instance of the SMTP transport mechanism
+ var restInstance = REST.GetInstance(new NetworkCredential(_username, _password));
+
+ //send the mail
+ restInstance.Deliver(message);
+ }
+ }
+}
diff --git a/SendGrid/Example/SMTPAPI.cs b/SendGrid/Example/SMTPAPI.cs new file mode 100755 index 0000000..b46520b --- /dev/null +++ b/SendGrid/Example/SMTPAPI.cs @@ -0,0 +1,202 @@ +using System;
+using System.Collections.Generic;
+using System.Net;
+using System.Net.Mail;
+using SendGridMail;
+using SendGridMail.Transport;
+
+namespace Example
+{
+ class SMTPAPI
+ {
+ private String _username;
+ private String _password;
+ private String _from;
+ private IEnumerable<string> _to;
+
+ public SMTPAPI(String username, String password, String from, IEnumerable<string> recipients)
+ {
+ _username = username;
+ _password = password;
+ _from = from;
+ _to = recipients;
+ }
+
+ /// <summary>
+ /// Send a simple HTML based email
+ /// </summary>
+ public void SimpleHTMLEmail()
+ {
+ //create a new message object
+ var message = SendGrid.GenerateInstance();
+
+ //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 = "<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 smtpInstance = SMTP.GenerateInstance(new NetworkCredential(_username, _password));
+
+ //send the mail
+ smtpInstance.Deliver(message);
+ }
+
+ /// <summary>
+ /// Send a simple Plain Text email
+ /// </summary>
+ public void SimplePlaintextEmail()
+ {
+ //create a new message object
+ var message = SendGrid.GenerateInstance();
+
+ //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.Text = "Hello World Plain Text";
+
+ //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));
+
+ //send the mail
+ smtpInstance.Deliver(message);
+ }
+
+ /// <summary>
+ /// Enable The Gravatar Filter.
+ /// Currently the filter a 1x1 pixel gravatar image.
+ /// Find more info at http://docs.sendgrid.com/documentation/apps/gravatar/
+ /// </summary>
+ public void EnableGravatarEmail()
+ {
+ //create a new message object
+ var message = SendGrid.GenerateInstance();
+
+ //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 Gravatar Email</p>";
+
+ //set the message subject
+ message.Subject = "Hello World Gravatar Test";
+
+ //create an instance of the SMTP transport mechanism
+ var smtpInstance = SMTP.GenerateInstance(new NetworkCredential(_username, _password));
+
+ //enable gravatar
+ message.EnableGravatar();
+
+ //send the mail
+ smtpInstance.Deliver(message);
+ }
+
+ /// <summary>
+ /// Enable the Open Tracking to track when emails are opened.
+ /// http://docs.sendgrid.com/documentation/apps/open-tracking/
+ /// </summary>
+ public void EnableOpenTrackingEmail()
+ {
+ var header = new Header();
+ //create a new message object
+ var message = SendGrid.GenerateInstance();
+
+ //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 Open Tracking 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());
+
+ //send the mail
+ smtpInstance.Deliver(message);
+
+ Console.WriteLine("done");
+ }
+
+ /// <summary>
+ /// Enable the Open Tracking to track when emails are opened.
+ /// http://docs.sendgrid.com/documentation/apps/open-tracking/
+ /// </summary>
+ public void EnableClickTrackingEmail()
+ {
+ var header = new Header();
+ //create a new message object
+ var message = SendGrid.GenerateInstance();
+
+ //set the message recipients
+ foreach (string recipient in _to)
+ {
+ message.AddTo(recipient);
+ }
+
+ //set the sender
+ message.From = new MailAddress(_from);
+
+ //set the message body
+ var timestamp = DateTime.Now.ToString("HH:mm:ss tt");
+ message.Html = "<p style='color:red';>Hello World Plain Text</p> <a href = 'http://microsoft.com'>Checkout Microsoft!!</a>";
+ message.Html += "<p>Sent At : " + timestamp + "</p>";
+
+ //set the message subject
+ message.Subject = "Hello World Click Tracking Test";
+
+ //create an instance of the SMTP transport mechanism
+ var smtpInstance = SMTP.GenerateInstance(new NetworkCredential(_username, _password));
+
+ //enable clicktracking
+ message.EnableClickTracking("1");
+
+ Console.WriteLine(header.AsJson());
+
+ //send the mail
+ smtpInstance.Deliver(message);
+
+ Console.WriteLine("done");
+ Console.WriteLine("Sent at : "+timestamp);
+ }
+
+ }
+}
diff --git a/SendGrid/Example/app.config b/SendGrid/Example/app.config new file mode 100755 index 0000000..e212038 --- /dev/null +++ b/SendGrid/Example/app.config @@ -0,0 +1,4 @@ +<?xml version="1.0"?>
+<configuration>
+<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup>
+</configuration>
|