0

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?

Mike Park
  • 10,845
  • 2
  • 34
  • 50
Kyle
  • 32,731
  • 39
  • 134
  • 184

1 Answers1

1

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/

Antonio Bakula
  • 20,445
  • 6
  • 75
  • 102