diff options
author | CJ Buchmann <cj.buchmann@sendgrid.com> | 2012-01-13 16:42:38 -0800 |
---|---|---|
committer | CJ Buchmann <cj.buchmann@sendgrid.com> | 2012-01-13 16:42:38 -0800 |
commit | cc7e8b7a0aae5381899ea1ea4c91e467f170348a (patch) | |
tree | d0062795c0cf8dc2f1abf2d0d8dc226a96809be7 /SendGrid/Example/RESTAPI.cs | |
parent | 2cc3f7ecf61374d9b88d41290fe29c04a3849d6c (diff) | |
parent | ba5a61b85f19027b240588216a6fc3d418214e04 (diff) | |
download | sendgrid-csharp-cc7e8b7a0aae5381899ea1ea4c91e467f170348a.zip sendgrid-csharp-cc7e8b7a0aae5381899ea1ea4c91e467f170348a.tar.gz sendgrid-csharp-cc7e8b7a0aae5381899ea1ea4c91e467f170348a.tar.bz2 |
Merge branch 'us1882' of github.com:sendgrid/sendgrid-csharp
Diffstat (limited to 'SendGrid/Example/RESTAPI.cs')
-rwxr-xr-x | SendGrid/Example/RESTAPI.cs | 95 |
1 files changed, 95 insertions, 0 deletions
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);
+ }
+ }
+}
|