blob: 31b6f7d37b32904b4502fdccde0c5980896ba0f8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.IO;
using System.IO.Pipes;
using System.Linq;
using System.Net;
using System.Net.Mail;
using System.Text;
namespace SendGridMail
{
class WebFileUpload
{
private HttpWebRequest _request;
private List<Attachment> _attachments;
private String newline = "\r\n";
private byte[] _boundaryBytes;
private String _boundary;
public WebFileUpload(HttpWebRequest request)
{
}
public void TestAddAttachment(Attachment attachment)
{
WebClient myWebClient = new WebClient();
NameValueCollection collection = new NameValueCollection();
StreamReader sr = new StreamReader(attachment.ContentStream);
var data = sr.ReadToEnd();
byte[] bytes = new byte[attachment.ContentStream.Length];
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)
{
_attachments.Add(new Attachment(filename));
}
public void AddAttachments(List<Attachment> attachments)
{
_attachments = attachments;
}
public List<Attachment> GetAttachments()
{
return _attachments;
}
public void SendAttachments()
{
WebResponse _response = null;
try
{
_response = _request.GetResponse();
//Stream stream = _response.GetResponseStream();
//StreamReader reader = new StreamReader(stream);
}
catch (Exception ex)
{
throw new Exception("Unable to send attachments :: " + ex.Message);
}
_response.Close();
}
}
}
|