I need an example code to send email with attachment using sendgrid Web API v3.
using (var client = new HttpClient())
{
client.BaseAddress = new Uri("https://api.sendgrid.com/");
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(
new MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(
"Basic",
Convert.ToBase64String(
Encoding.ASCII.GetBytes(String.Format("{0}:{1}",
credentials.UserName, credentials.Password))));
var data = new NewTemplate()
{
html_content = "<%body%>",
name = template.name + "_" + template.Versions.Count(),
plain_content = "<%body%>",
subject = "<%subject%>"
};
var content = JsonConvert.SerializeObject(data) as string;
var response = await client.PostAsync(
String.Format("v3/templates/{0}/versions", template.id),
new StringContent(content,Encoding.UTF8,"application/json"));
}
In the above code, authentication is done via UserName and Password. I need to change to authenticate via APIKey.