Sendgrid-csharp: ASP.Net 5 Support

Created on 27 Jun 2015  Â·  35Comments  Â·  Source: sendgrid/sendgrid-csharp

Are there plans for ASP.Net 5 support at the moment? I'm developing an application using ASP.Net 5, and I'd like to avoid writing my own SendGrid client if I could.

Most helpful comment

@OfficerJonez No problem with your code except that only solves a tiny part of the problem. It's also wound up as a top hit for this in Google results now.

There's a StrongGrid library on NuGet, it worked fine for me. SendGrid should just make that the official one and stop wasting everyone's time with this nonsense.

All 35 comments

+1 for me and I also believe for many others who plan to develop on ASP.NET 5.

I don't use ASP.NET so my understanding is limited, but can't you use any .NET DLL as normal? Is there something specific that needs to be done for ASP.NET 5 support?

Can you show me an example of something that is not working?

Hello,

the essence of the issue is to prepare a library targeting .NET Core on which ASP.NET 5 builds as specific app framework as is best explained in article at http://oren.codes/2015/07/29/targeting-net-core/ by Oren Novotny. "Legacy" .NET 4.x libraries can be used by ASP.NET 5 but only on Windows while for Linux and Mac support it is necessary to produce a .NET Core library as described in the article.

P. S. Over time .NET Core will become equality important on Windows as for example cloud optimized Windows Nano Server coming next year will only support .NET Core running on CoreCLR and no more "legacy" .NET Framework 4.x.

@mw2nukeboy In the meantime until .NET Core targeting SendGrid library gets out, you can target Desktop CLR with ASP.NET 5 on Windows and utilize "legacy" libraries. I am presently doing the same with RavenDB client library.

Okay thanks, I will see what I can do!

On Thu, Sep 3, 2015, 10:04 AM Jan Sichula [email protected] wrote:

@mw2nukeboy https://github.com/mw2nukeboy In the meantime until .NET
Core targeting SendGrid library gets out, you can target Desktop CLR with
ASP.NET 5 on Windows and utilize "legacy" libraries. I am presently doing
the same with RavenDB client library.

—
Reply to this email directly or view it on GitHub
https://github.com/sendgrid/sendgrid-csharp/issues/146#issuecomment-137496381
.

Currently, SendGrid doesn't support .NET Core 5.0. Since ASP.NET 5 isn't
expected to go to RC until November at the earliest (see
https://github.com/aspnet/Home/wiki/Roadmap), I think it may be a bit early
to have a version of SendGrid that supports .NET Core 5.0. It's something
that will need to be done, though.

If you aren't doing a cross-server deployment, you should be able to target
dnx451 and/or dnx46 with your application. You can remove the dnxcore50
framework reference from you project.json folder until SendGrid releases a
version a compatible version.

On Thu, Sep 3, 2015 at 10:48 AM, Brandon West [email protected]
wrote:

I don't use ASP.NET so my understanding is limited, but can't you use any
.NET DLL as normal? Is there something specific that needs to be done for
ASP.NET 5 support?

—
Reply to this email directly or view it on GitHub
https://github.com/sendgrid/sendgrid-csharp/issues/146#issuecomment-137491079
.

Do we have some updates here? ASP.NET 5 is already rc1-update1

@artemgrygor This is not our short term roadmap; however, I'm leaving this ticket open for future planning.

I am also developing an application for core and would like to use sendgrid. Please consider adding support. Thank you.

+1 for me, since many of our apps are being developed .netcore.

Same here, specially after the policy of mandril i'm moving everything from mailchimp/mandrill to sendgrid. Core support will be a must in a short time period. Any updates?

Adding another voice to the choir. Tried this today and sadly it still isn't implemented yet.

+1 for me as well.

+1 for me as well.

+1

How can we help?

It looks like the biggest problem with supporting .NET Core is it's missing System.Net.Mail library.

One solution would be to use MimeKit although that would require breaking changes in the ISendGrid interface. (All MailAddress references would have to be changed to MailboxAddress and MimeMessage instead of MailMessage)

Could a second .Net library (sendgrid-coreclr) be added perhaps that uses MimeKit for all the ASP.Net Core 1.0 users?

Just my two cents, let us know if we can help.

Hello Everyone,

Thank you for the continued feedback on this.

The new SendGrid C# library will be based on this client: https://github.com/sendgrid/csharp-http-client

The library itself will mainly consist of helper functions to make using our Web API as easy as possible.

Do you see anything in the client that would make it difficult to support .NET Core?

Thanks for your continued support!

@thinkingserious Thanks for sharing your plans!

I don't see anything major in csharp-http-client that would be a issue. Just JavaScriptSerializer to use JsonConvert.DeserializeObject from Newtonsoft.Json instead and HttpUtility.ParseQueryString to use QueryHelpers.ParseQuery from Microsoft.AspNet.WebUtilities.

:smile:

@PaitoAnderson thanks for the feedback!

Could you please give me some background on your suggestions? Particularly the first one. I know that Newtonsoft.Json is very popular, but one of our goals was to reduce our outside dependencies as much as possible. That said, we are open to changes given some justification.

Thanks for taking the time to take a look! We greatly appreciate your support!

Newtonsoft.Json is the facto library on asp.net core.

the other is just a move/rename for running on core afaik.

Thanks for the feedback @Bartmax!

It seems like .NET Core now includes it's own JSON library within CoreFX: https://github.com/dotnet/corefx/tree/master/src/System.Runtime.Serialization.Json

Do you have any reference regarding Newtonsoft.Json being the standard for .NET Core?

Thanks in advance!

For reference checkout https://github.com/dotnet/corefx/blob/master/Documentation/project-docs/glossary.md and navigate to the JSON.NET section, it's also a dependency of some other MS libraries like https://www.nuget.org/packages/Microsoft.AspNet.WebApi.Client/. I am not sure System.Runtime.Serialization.Json is fully baked yet either.

Here is an example of what this library might look like if it supported .Net 4.5.1 and .Net Core, notice how it can use either Newtonsoft.Json or System.Web.Script.Serialization depending on the framework.

https://github.com/PaitoAnderson/csharp-http-client

Maybe looking at this make sense on why this isn't an _external dependency_ you might have to worry about:

image

the list goes on :)

Awesome feedback everyone!

I've added an issue to the csharp-http-client to get this on our roadmap.

Hello Everyone,

I am trying to add SendGrid reference from Nuget Package in .NetCore Library Project and getting Following Error:
NU1001 The Dependency Sendgrid 8.04 could not be resolved.
Is there any solution for adding SendGrid refrence in the .NetCore library Project?

Hi @nipundigitech,

I have not dug deep into this yet, but you can follow our progress here: https://github.com/sendgrid/sendgrid-csharp/issues/221

This is a high priority issue for us and it is near the top of our backlog. I've added your vote to the ticket (which helped it jump a few slots up :))

Not really hard to implement yourself...

1) Create your MailObject, Personalization Object, email object

public class MailObject
    {
        public ICollection<MailPersonalizations> personalizations { get; set; }
        public Email from { get; set; }
        public string template_id { get; set; }
        //public ICollection<MailContent> content { get; set; }
    }
public class MailPersonalizations
    {
        public ICollection<Email> to { get; set; }
        public string subject { get; set; }
        public Dictionary<string, string> substitutions { get; set; }
    }
public class Email
    {
        public string email { get; set; }
        public string name { get; set; }
    }

2) Init your object and send with HttpClient... Not worth including library (my opinion)

SEND EMAIL USING SENDGRID API

using(var client = new HttpClient())
    {
        var jsonMail = JsonConvert.SerializeObject(mailObject);//convert object

        client.DefaultRequestHeaders.Accept.Clear(); //Clear headers
        client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); //Add Accept type
        client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", "API key"); //Add Authorization

        var response = await client.PostAsync("https://api.sendgrid.com/v3/mail/send", new StringContent(jsonMail, Encoding.UTF8, "application/json")); //Send the mail
    }

Hello @OfficerJonez,

I hope you don't mind that I took the liberty to format your comment for readability :)

We agree that not everyone wants to use a library to interact and we appreciate that you took the time to provide working code to help others. So if you don't mind, please fill out this form and we will send some swag your way.

For those that are looking for the library to support .NET Core, please follow this thread. This work is currently in progress in this branch and will be merged into the v9beta branch when complete. The v9beta project can be viewed in it's entirety here.

Thank you for your support!

@thinkingserious
Thanks for offering some swag :), first time I placed some comments on a sendgrid post.
So I checked the layout changes

I spended a lot of time upgrading solutions to .net core V1.1, which also includes SendGrid.
It's hard to find good sendgrid examples using templates and substitution, so if I can help out a bit.

Great way to send customized mails for registrations etc... Once you got the knowledge

@OfficerJonez,

Awesome!

Here is a first crack on providing some examples for templates and substitutions. That's a common issue: https://github.com/sendgrid/sendgrid-csharp/blob/master/USE_CASES.md#transactional_templates

Here it is without the dynamic stuff (v9): https://github.com/sendgrid/sendgrid-csharp/blob/v9beta/USE_CASES.md#transactional_templates

We actively listen and incorporate feedback. If there is a specific issue you would like see resolved, just open an issue or upvote a current one. If are so inclined, we also greatly appreciate pull requests.

Thanks again!

Just landed on this thread via Google. 18 months later the idiotic SendGrid library STILL doesn't work in .NET Core. Lots of nonsense talk above but it would just work today with no code changes. However the NuGet package is hardcoded looking for v0.0 of the framework. Amateur hour.

But hey, a code snippet is provided! And @thinkingserious is handing out swag so it must be good. Of course the code doesn't work. The MailContent object is commented out.

I just can't even. #317. @mbernier

Merry Christmas everyone. I look forward to watching this library make absolutely zero forward progress with all of you in 2017.

My code is just an example how you can send templates without the library (since its not working).

Whenever you use templates, you don't the MailContent object

And btw you can create the object just by reading the API docs.

@OfficerJonez No problem with your code except that only solves a tiny part of the problem. It's also wound up as a top hit for this in Google results now.

There's a StrongGrid library on NuGet, it worked fine for me. SendGrid should just make that the official one and stop wasting everyone's time with this nonsense.

Hello everyone,

BIG thanks to all of those that have contributed on this thread, we greatly appreciate your patience and support!

The v9beta branch has been pushed to Nuget as a prerelease for testing. Please give it a spin and let us know what you think :)

The main updates are:

  • Removed dynamic dependencies
  • Added support for .NET Standard 1.3
  • Updated the Mail Helper for better UX/DX

Here is what we think needs to be completed before we exit beta:

  • A few weeks of iterative improvements based on your feedback and internal testing
  • Updated docs (USAGE, USE_CASES, TROUBLESHOOTING, CONTRIBUTING, /examples and the Helper Example)
  • Update the auto-generated portions of the tests to use CamelCase function names
  • Move from Travis to Appveyor
  • Implement SendSingleEmailToMultipleRecipientsAsync
  • Implement SendMultipleEmailsToMultipleRecipientsAsync
  • Adopt StyleCop

The remainder of our wants for this version will be added to GitHub as issues.

With Best Regards,

Elmer

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lijaso picture lijaso  Â·  3Comments

CalvinFengDatacom picture CalvinFengDatacom  Â·  4Comments

bogacg picture bogacg  Â·  3Comments

eat-sleep-code picture eat-sleep-code  Â·  3Comments

mawiseman picture mawiseman  Â·  4Comments