I am wanting to attach a file as an attachment using SendGrid and C# - I have the code below which runs but the response.StatusCode
that is returned is
BadResponse
How do I alter this code so that the file is attached and an email sent successfully?
var msg = MailHelper.CreateSingleEmail(from, to, subject, plainTextContent, htmlContent);
var listAtta = new List<FileAttachment>();
emailProducts.Select(o => o.tp).ToList().ForEach(o =>
{
string file = o.ProductPdf;
var fileBytes = FileToByteArray(o.ProductPdf);
if (fileBytes != null && fileBytes.Count() > 0)
{
listAtta.Add(new FileAttachment
{
FileData = fileBytes,
FileName = o.ProductPdf
}); ;
}
msg.AddAttachment(o.ProductPdf, fileBytes.ToString());
});
var response = await client.SendEmailAsync(msg);
var success = response.StatusCode;