I am trying to use sendgrid's web API. To use it, you do a get request to a URL that looks like this
sendgrid.com/api/mail.send.json?to=example%40exaple.com&from=example%40example&subject=Subject&text=Body&files=files%5Bfile1.doc%5D%3Dexample.doc%26files%5Bfile2.pdf%5D%3Dexample.pdf&api_user=usnermae&api_key=apikey
What confuses me is the files part:
&files=files%5Bfile1.doc%5D%3Dexample.doc%26files%5Bfile2.pdf%5D%3Dexample.pdf&api_user=usnermae&api_key=apikey
In c# code, how would I give a file that I have in a stream or byte[] to a url?
This is how I am performing the request in the end.
using (WebClient client = new WebClient())
{
string text = client.DownloadString(url);
}
This so far works fine, and I have everything programed in except for the attachments. Can anyone point me in the right direction for how to get files into the URL for a get request?
You should use WebClient.UploadFile
method but why not simply use SendGrid stmp server ? Then send this mail as any other mail with SmtpClient
, here is the example :
http://www.mattpaulson.com/2011/01/using-sendgrid-in-asp-net/
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.