Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't Include Empty Objects in JSON Request Body #297

Closed
LorenDorez opened this issue Aug 5, 2016 · 5 comments
Closed

Don't Include Empty Objects in JSON Request Body #297

LorenDorez opened this issue Aug 5, 2016 · 5 comments
Labels
status: help wanted requesting help from the community type: community enhancement feature request not on Twilio's roadmap

Comments

@LorenDorez
Copy link

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("ovesii_demo@greenlight-software.com") };
                //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";
        }
@LorenDorez
Copy link
Author

this is my response from the myMessage.Get()

{"from":{"email":"info@oversii.com"},"subject":"07/31/2016 - Arbor Walk - DEMO Patrol Report","personalizations":[{"to":[{"email":"ovesii_demo@greenlight-software.com"}],"bcc":[]}],"content":[{"type":"text/html","value":"\u003c!DOCTYPE html\u003e\r\n\u003chtml lang=\u0022en\u0022 xmlns=\u0022http://www.w3.org/1999/xhtml\u0022\u003e\r\n\u003chead\u003e\r\n    \u003cmeta charset=\u0022utf-8\u0022 /\u003e\r\n    \u003ctitle\u003e07/31/2016 - Arbor Walk - DEMO Patrol Report\u003c/title\u003e\r\n\u003c/head\u003e\r\n\u003cbody\u003e\r\n    Greetings Property Manager,\r\n\u003cbr /\u003e\r\n\u003cbr /\u003e\r\nPlease see the \u003cstrong\u003eArbor Walk - DEMO\u003c/strong\u003e Patrol Report Data for  \u003cstrong\u003e07/31/2016\u003c/strong\u003e herein:\r\n\u003cbr /\u003e\r\n\u003cbr /\u003e\r\n1) Patrol Report (Excel).\r\n\u003cbr /\u003e\r\n\u003cbr /\u003e\r\n\u003cbr /\u003e\r\nNote: To access your GPS Report and Pictures, please select Evidence on the online system at oversii.com\u003cbr /\u003e\r\n\u003cbr /\u003e\r\n\u003cbr /\u003e\r\n\u003cbr /\u003e\r\nOversii\u003cbr /\u003e\r\nOffice:  866.506.5759\r\n\u003cbr /\u003e\r\nFax:     866.506.5759\r\n\u003cbr /\u003e\r\n\u003cbr /\u003e\r\n\u003ca href=\u0022\\\u0022\u003eInfo@oversii.com\u003c/a\u003e\r\n\u003cbr /\u003e\r\n\u003ca href=\u0022\\\u0022\u003ewww.oversii.com\u003c/a\u003e\r\n\u003cbr /\u003e\r\n\u003cbr /\u003e\r\nNotice of Confidentiality: The information transmitted is intended only for the person or entity to whom it is addressed and may contain confidential and/or privileged material. Any review, retransmission, dissemination or other use of, or taking any action in reliance upon, this information by anyone other than the intended recipient is not authorized.\r\n\r\n    \u003cbr /\u003e\r\n    \u003cbr /\u003e\r\n    \u003cspan\u003eRegards,\u003c/span\u003e\r\n    \u003cbr /\u003e\r\n    \u003cbr /\u003e\r\n    Oversii\u003cbr /\u003e\r\n    Office: 866.506.5759\u003cbr /\u003e\r\n    Fax: 866.506.5759\u003cbr /\u003e\r\n    \u003cbr /\u003e\r\n    \u003ca href=\u0022mailto:info@oversii.com\u0022\u003einfo@oversii.com\u003c/a\u003e\r\n    \u003cbr /\u003e\r\n    \u003ca href=\u0022http://www.oversii.com\u0022\u003ewww.oversii.com\u003c/a\u003e\r\n\r\n\r\n    \u003cp\u003e\r\n        \u003cstrong\u003eNotice of Confidentiality:\u003c/strong\u003e\r\n        The information transmitted is intended only for the person or entity to whom it is addressed and may contain confidential and/or privileged material. Any review, retransmission, dissemination or other use of, or taking any action in reliance upon, this information by anyone other than the intended recipient is not authorized.\r\n    \u003c/p\u003e\r\n\u003c/body\u003e\r\n\u003c/html\u003e"}]}

@LorenDorez
Copy link
Author

After much Trail and error this is caused by the blank BCCs.

When in development i Clear the BCCs using personalization.Bccs.Clear();

however this appear to still output BCCs in the json

@thinkingserious
Copy link
Contributor

@LorenDorez,

Thank you for following up! I will leave this ticket open so that we can adjust the Mail Helper such that empty objects are not included.

For your help, we would like to send you a token of our appreciation. Could you please email us at dx@sendgrid.com with your T-shirt size and mailing address?

Thanks!

@thinkingserious thinkingserious added type: community enhancement feature request not on Twilio's roadmap status: help wanted requesting help from the community labels Aug 6, 2016
@thinkingserious thinkingserious changed the title Email not being sent Don't Include Empty Objects in JSON Request Body Aug 6, 2016
@LorenDorez
Copy link
Author

Thanks Email sent.

@thinkingserious
Copy link
Contributor

dubrovkinmaxim pushed a commit to dubrovkinmaxim/sendgrid-csharp that referenced this issue Sep 20, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: help wanted requesting help from the community type: community enhancement feature request not on Twilio's roadmap
Projects
None yet
Development

No branches or pull requests

2 participants