-
Notifications
You must be signed in to change notification settings - Fork 575
Don't Include Empty Objects in JSON Request Body #297
Copy link
Copy link
Closed
Labels
status: help wantedrequesting help from the communityrequesting help from the communitytype: community enhancementfeature request not on Twilio's roadmapfeature request not on Twilio's roadmap
Description
I switched from v2 to V3 and the API call to send appears to work but im not receiving any emails. The HTTP response comes back as bad request but everything looks good
public async Task SendEmailAsync(IEnumerable<string> toAddresses, IEnumerable<string> bccAddresses, string fromAddress, string subject, string message, string[] attachments)
{
// Plug in your email service here to send an email.
Mail myMessage = new Mail();
Personalization personalization = new Personalization();
foreach (string toAddress in toAddresses)
{
personalization.AddTo(new Email(toAddress));
}
if (bccAddresses != null && bccAddresses.Count() > 0)
{
foreach (string bccAddress in bccAddresses)
{
personalization.AddBcc(new Email(bccAddress));
}
}
myMessage.From = new Email(fromAddress);
myMessage.Subject = subject;
//myMessage.AddContent(new Content("text/plain", message));
myMessage.AddContent(new Content("text/html", message));
foreach (string filePath in attachments)
{
string fileContents = Convert.ToBase64String(File.ReadAllBytes(filePath));
string contentType;
new FileExtensionContentTypeProvider().TryGetContentType(filePath, out contentType);
contentType = contentType ?? "application/octet-stream";
Attachment attachment = new Attachment();
attachment.Content = fileContents;
attachment.Type = contentType;
attachment.Filename = Path.GetFileName(filePath);
attachment.Disposition = "attachment";
//myMessage.AddAttachment(attachment);
}
//DEMO OVERRIDE
if (_hostingEnvironment.IsDevelopment())
{
personalization.Tos = new List<Email> { new Email("[email protected]") };
//personalization.Ccs.Clear();
personalization.Bccs.Clear();
}
myMessage.AddPersonalization(personalization);
// Create a Web transport for sending email.
dynamic sg = new SendGridAPIClient(Options.SendGridApiKey);
//return transportWeb.client.mail.send.postDeliverAsync(myMessage);
dynamic response = await sg.client.mail.send.post(requestBody: myMessage.Get());
var t1 = myMessage.Get();
var str = "test";
}
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
status: help wantedrequesting help from the communityrequesting help from the communitytype: community enhancementfeature request not on Twilio's roadmapfeature request not on Twilio's roadmap