1
I am in need of an example code for sending 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.
Have you tried searching google? https://sendgrid.com/docs/API_Reference/Web_API_v3/Mail/index.html
– PauloHDSousa
Paulohdsousa, thanks for the link. I had already found this link, but I could not make it work with sending attachment.
– b3r3ch1t
Put your code in the question and which error is giving.
– Pablo Tondolo de Vargas