summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTyler Bischel <tyler.bischel@sendgrid.com>2012-01-09 14:10:10 -0800
committerTyler Bischel <tyler.bischel@sendgrid.com>2012-01-09 14:10:10 -0800
commit0b8728acd40b3b1d0e980f4989e7a2f060b4df30 (patch)
treefe4f923ef084b8f62344f15535c05370d7163376
parent24ad1b3dc7384093d5b9bf74cef21e595c978833 (diff)
downloadsendgrid-csharp-0b8728acd40b3b1d0e980f4989e7a2f060b4df30.zip
sendgrid-csharp-0b8728acd40b3b1d0e980f4989e7a2f060b4df30.tar.gz
sendgrid-csharp-0b8728acd40b3b1d0e980f4989e7a2f060b4df30.tar.bz2
added David McGuires implementation of the SMTP wrapper
-rwxr-xr-xSendGrid/SendGrid/Transport/SMTP.cs69
1 files changed, 69 insertions, 0 deletions
diff --git a/SendGrid/SendGrid/Transport/SMTP.cs b/SendGrid/SendGrid/Transport/SMTP.cs
new file mode 100755
index 0000000..ce03250
--- /dev/null
+++ b/SendGrid/SendGrid/Transport/SMTP.cs
@@ -0,0 +1,69 @@
+using System;
+using System.Net;
+using System.Net.Mail;
+
+namespace SendGrid.Transport
+{
+ /// <summary>
+ /// Transport class for delivering messages via SMTP
+ /// </summary>
+ public class SMTP : ITransport
+ {
+ /// <summary>
+ /// SendGrid's host name
+ /// </summary>
+ public const String SmtpServer = "smtp.sendgrid.net";
+
+ /// <summary>
+ /// Port for Simple Mail Transfer Protocol
+ /// </summary>
+ public const Int32 Port = 25;
+
+ /// <summary>
+ /// Port for Secure SMTP
+ /// </summary>
+ public const Int32 SslPort = 465;
+
+ /// <summary>
+ /// Port for TLS (currently not supported)
+ /// </summary>
+ public const Int32 TlsPort = 571;
+
+ /// <summary>
+ /// Client used to deliver SMTP message
+ /// </summary>
+ private readonly SmtpClient _client;
+
+ /// <summary>
+ /// Transport created to deliver messages to SendGrid using SMTP
+ /// </summary>
+ /// <param name="credentials">Sendgrid user credentials</param>
+ /// <param name="host">MTA recieving this message. By default, sent through SendGrid.</param>
+ /// <param name="port">SMTP port 25 is the default. Port 465 can be used for Secure SMTP.</param>
+ public SMTP(NetworkCredential credentials, String host = SmtpServer, Int32 port = Port)
+ {
+ _client = new SmtpClient(host, port) {Credentials = credentials, DeliveryMethod = SmtpDeliveryMethod.Network};
+
+ switch (port)
+ {
+ case Port:
+ break;
+ case SslPort:
+ _client.EnableSsl = true;
+ break;
+ case TlsPort:
+ throw new NotSupportedException("TLS not supported");
+ }
+ }
+
+ /// <summary>
+ /// Deliver an email using SMTP protocol
+ /// </summary>
+ /// <param name="message"></param>
+ public void Deliver(ISendGrid message)
+ {
+ var mime = message.CreateMimeMessage();
+ _client.Send(mime);
+ }
+ }
+}