diff options
-rwxr-xr-x | SendGrid/Example/Program.cs | 5 | ||||
-rwxr-xr-x | SendGrid/SendGridMail/Mail.csproj | 3 | ||||
-rwxr-xr-x | SendGrid/SendGridMail/Transport/REST.cs | 5 | ||||
-rwxr-xr-x | SendGrid/SendGridMail/WebFileUpload.cs | 57 |
4 files changed, 62 insertions, 8 deletions
diff --git a/SendGrid/Example/Program.cs b/SendGrid/Example/Program.cs index 1953312..0bdaacd 100755 --- a/SendGrid/Example/Program.cs +++ b/SendGrid/Example/Program.cs @@ -13,7 +13,7 @@ namespace Example {
static void Main(String[] args)
{
- var restInstance = REST.GetInstance(new NetworkCredential("sgrid_username", "sgrid_email"));
+ var restInstance = REST.GetInstance(new NetworkCredential("cjbuchmann", "Gadget_15"));
//create a new message object
var message = SendGrid.GenerateInstance();
@@ -24,7 +24,8 @@ namespace Example message.Subject = "Hello World SUbject";
message.AddAttachment(@"D:\att_proj\21.jpg");
- restInstance.Deliver(message);
+ //restInstance.Deliver(message);
+ restInstance.TestDeliver(message);
Console.WriteLine("Message Sent");
Console.WriteLine("DONE!");
diff --git a/SendGrid/SendGridMail/Mail.csproj b/SendGrid/SendGridMail/Mail.csproj index 6fa65bb..5d422b9 100755 --- a/SendGrid/SendGridMail/Mail.csproj +++ b/SendGrid/SendGridMail/Mail.csproj @@ -31,6 +31,9 @@ <WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
+ <Reference Include="CodeScales.Http">
+ <HintPath>..\..\..\references\CodeScales.Http.dll</HintPath>
+ </Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Net" />
diff --git a/SendGrid/SendGridMail/Transport/REST.cs b/SendGrid/SendGridMail/Transport/REST.cs index 52fe336..3bb23a6 100755 --- a/SendGrid/SendGridMail/Transport/REST.cs +++ b/SendGrid/SendGridMail/Transport/REST.cs @@ -48,6 +48,11 @@ namespace SendGridMail.Transport _query.Add(new KeyValuePair<string, string>(key, value));
}
+ public void TestDeliver(ISendGrid Message)
+ {
+ new WebFileUpload(null).SendAttachments();
+ }
+
public void Deliver(ISendGrid message)
{
// TODO Fix this to include all recipients
diff --git a/SendGrid/SendGridMail/WebFileUpload.cs b/SendGrid/SendGridMail/WebFileUpload.cs index 31b6f7d..c7b5165 100755 --- a/SendGrid/SendGridMail/WebFileUpload.cs +++ b/SendGrid/SendGridMail/WebFileUpload.cs @@ -7,10 +7,15 @@ using System.Linq; using System.Net;
using System.Net.Mail;
using System.Text;
+using CodeScales.Http;
+using CodeScales.Http.Common;
+using CodeScales.Http.Entity;
+using CodeScales.Http.Entity.Mime;
+using CodeScales.Http.Methods;
namespace SendGridMail
{
- class WebFileUpload
+ internal class WebFileUpload
{
private HttpWebRequest _request;
private List<Attachment> _attachments;
@@ -23,10 +28,50 @@ namespace SendGridMail public WebFileUpload(HttpWebRequest request)
{
-
+
}
- public void TestAddAttachment(Attachment attachment)
+ public void SendAttachments()
+ {
+ HttpClient client = new HttpClient();
+ //https://sendgrid.com/api/mail.send
+ var url = "http://sendgrid.com/api/mail.send.xml";
+ var notUrl = "http://www.postbin.org/1hv8rbe";
+ HttpPost postMethod = new HttpPost(new Uri(url));
+
+
+
+ //UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(nameValuePairList, Encoding.UTF8);
+ //postMethod.Entity = formEntity;
+
+
+
+ MultipartEntity multipartEntity = new MultipartEntity();
+ postMethod.Entity = multipartEntity;
+
+ multipartEntity.AddBody(new StringBody(Encoding.UTF8, "api_user", "cjbuchmann"));
+ multipartEntity.AddBody(new StringBody(Encoding.UTF8, "api_key", "gadget15"));
+ multipartEntity.AddBody(new StringBody(Encoding.UTF8, "to", "cj.buchmann@sendgrid.com"));
+ multipartEntity.AddBody(new StringBody(Encoding.UTF8, "from", "cj.buchmann@sendgrid.com"));
+ multipartEntity.AddBody(new StringBody(Encoding.UTF8, "subject", "Hello World HttpClient Test"));
+ multipartEntity.AddBody(new StringBody(Encoding.UTF8, "text", "here is some awesome text"));
+
+
+
+ FileInfo fileInfo = new FileInfo(@"D:\att_proj\2.JPG");
+ FileBody fileBody = new FileBody("files[file1.jpg]", "myfile.jpg", fileInfo);
+
+ multipartEntity.AddBody(fileBody);
+
+ HttpResponse response = client.Execute(postMethod);
+
+ Console.WriteLine("Response Code: " + response.ResponseCode);
+ Console.WriteLine("Response Content: " + EntityUtils.ToString(response.Entity));
+
+ Console.WriteLine("done");
+ }
+
+ /*public void TestAddAttachment(Attachment attachment)
{
WebClient myWebClient = new WebClient();
NameValueCollection collection = new NameValueCollection();
@@ -37,7 +82,7 @@ namespace SendGridMail byte[] responseArray = myWebClient.UploadValues("https://sendgrid.com/api/mail.send.xml", collection);
Console.WriteLine("\nResponse received was :\n{0}", Encoding.ASCII.GetString(responseArray));
- }
+ }*/
public void AddAttachment(String filename)
{
@@ -54,7 +99,7 @@ namespace SendGridMail return _attachments;
}
- public void SendAttachments()
+ /*public void SendAttachments()
{
WebResponse _response = null;
@@ -71,6 +116,6 @@ namespace SendGridMail }
_response.Close();
- }
+ }*/
}
}
|