Skip to content

Cannot send transactional mails via Sendgrid C# #319

@Fumunchu

Description

@Fumunchu

Issue Summary

I am trying to create a bulk mailer, I found the following article in the community docs to create the JSON required as specified by the Transactional API Documentation. https://community.sendgrid.com/sendgrid/topics/_net_c_cshap_api?from_gsfn=true My class Returns the following.

{X-SMTPAPI: {
  "to": [
    "jacques.bronkhorst@tlhsoftware.com"
  ],
  "filters": {
    "templates": {
      "settings": {
        "enable": 1,
        "template_id": "2678f5e7-8ced-4336-b86f-5e17e51385a4"
      }
    }
  },
  "sub": {
    "-Person-": [
      "Jacques Bronkhorst"
    ],
    "-WebLink-": [
      "http://transcommercial.co.za/RequestDetail?r=97ae6a6a-b39e-408d-b9a0-2643c4552fa0"
    ]
  },
  "category": [
    "Request"
  ]
}}

I then created a small class to handle the mail, based on this code: https://github.com/sendgrid/sendgrid-csharp/blob/master/examples/mail/mail.cs

using System;
using SendGrid;
using SendGrid.Helpers.Mail;
using System.Threading.Tasks;
using Newtonsoft.Json;

namespace Transcommercial.Tools
{
    internal class SendGridMailer
    {
        public void Main(string Data)
        {
        Execute(Data).Wait();
    }

    static async Task Execute(string data)
    {
        string _apiKey = Environment.GetEnvironmentVariable("My APi Key That Has Full Access On Everything", EnvironmentVariableTarget.User);
        dynamic sg = new SendGrid.SendGridAPIClient(_apiKey);

        dynamic response = await sg.client.mail.get();
        //dynamic response = await sg.client.mail.send.post(requestBody: data);

    }
}
}

When debugging the mail.get() method I get the following message:

{Connection: keep-alive 
Access-Control-Allow-Methods: OPTIONS 
Access-Control-Max-Age: 21600 
Access-Control-Expose-Headers: Link 
Access-Control-Allow-Origin: * 
Access-Control-Allow-Headers: AUTHORIZATION, Content-Type, On-behalf-of, x-sg-elas-acl 
Content-Security-Policy: default-src https://api.sendgrid.com; frame-src 'none'; object-src 'none' 
X-Content-Type-Options: nosniff 
Strict-Transport-Security: max-age=31536000 
Date: Thu, 15 Sep 2016 12:12:42 GMT 
Server: nginx 
}

When debugging the mail.send.post() method I get the following Message:

{Connection: keep-alive 
X-Frame-Options: DENY 
Date: Thu, 15 Sep 2016 12:17:40 GMT 
Server: nginx 
}

I have also asked this question on Stack: https://stackoverflow.com/questions/39511599/cannot-send-transactional-mails-via-sendgrid-c-sharp
Any Ideas?

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: questionquestion directed at the library

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions