All Projects → sendgrid → Sendgrid Csharp

sendgrid / Sendgrid Csharp

Licence: mit
The Official Twilio SendGrid Led, Community Driven C#, .NetStandard, .NetCore API Library

Projects that are alternatives of or similar to Sendgrid Csharp

Alexa Skills Dotnet
An Amazon Alexa Skills SDK for .NET
Stars: ✭ 412 (-50.66%)
Mutual labels:  dotnet-standard, dotnet-core, dotnetcore
Dotnet Etcd
A C# .NET (dotnet) GRPC client for etcd v3 +
Stars: ✭ 157 (-81.2%)
Mutual labels:  dotnet-standard, dotnet-core, dotnetcore
Sio.core
✔ [ SIOC ] Swastika I/O Core is an all in one platform (e.g CMS, eCommerce, Forum, Q&A, CRM...) ASP.NET Core / Dotnet Core System based on SIOH Framework.
Stars: ✭ 121 (-85.51%)
Mutual labels:  dotnet-standard, dotnet-core, dotnetcore
Sendgrid Nodejs
The Official Twilio SendGrid Led, Community Driven Node.js API Library
Stars: ✭ 2,543 (+204.55%)
Mutual labels:  transactional-emails, email, sendgrid
Sendgrid Go
The Official Twilio SendGrid Led, Community Driven Golang API Library
Stars: ✭ 710 (-14.97%)
Mutual labels:  transactional-emails, email, sendgrid
Raft.net
Implementation of RAFT distributed consensus algorithm among TCP Peers on .NET / .NETStandard / .NETCore / dotnet
Stars: ✭ 112 (-86.59%)
Mutual labels:  dotnet-standard, dotnet-core, dotnetcore
Appmetrics
App Metrics is an open-source and cross-platform .NET library used to record and report metrics within an application.
Stars: ✭ 1,986 (+137.84%)
Mutual labels:  dotnet-standard, dotnet-core, dotnetcore
Wopihost
ASP.NET Core MVC implementation of the WOPI protocol. Enables integration with WOPI clients such as Office Online Server.
Stars: ✭ 132 (-84.19%)
Mutual labels:  dotnet-standard, dotnet-core, dotnetcore
Sharpsnmplib
Sharp SNMP Library- Open Source SNMP for .NET and Mono
Stars: ✭ 247 (-70.42%)
Mutual labels:  dotnet-standard, dotnet-core, dotnetcore
Corehook
A library that simplifies intercepting application function calls using managed code and the .NET Core runtime
Stars: ✭ 191 (-77.13%)
Mutual labels:  dotnet-standard, dotnet-core, dotnetcore
Sendgrid Php
The Official Twilio SendGrid Led, Community Driven PHP API Library
Stars: ✭ 1,257 (+50.54%)
Mutual labels:  transactional-emails, email, sendgrid
Awesome Cms Core
Awesome CMS Core is an open source CMS built using ASP.Net Core & ReactJS with module seperation concern in mind and provide lastest trend of technology like .Net Core, React, Webpack, SASS, Background Job, Message Queue.
Stars: ✭ 352 (-57.84%)
Mutual labels:  dotnet-standard, dotnet-core, dotnetcore
Sendgrid Python
The Official Twilio SendGrid Led, Community Driven Python API Library
Stars: ✭ 1,125 (+34.73%)
Mutual labels:  transactional-emails, email, sendgrid
Sendgrid Ruby
The Official Twilio SendGrid Led, Community Driven Ruby API Library
Stars: ✭ 520 (-37.72%)
Mutual labels:  transactional-emails, email, sendgrid
Fluentemail
All in one email sender for .NET. Supports popular senders (SendGrid, MailGun, etc) and Razor templates.
Stars: ✭ 1,888 (+126.11%)
Mutual labels:  email, sendgrid, dotnetcore
Rafty
Implementation of RAFT consensus in .NET core
Stars: ✭ 182 (-78.2%)
Mutual labels:  dotnet-standard, dotnet-core, dotnetcore
Magento2 Gmail Smtp App
Configure Magento 2 to send email using Google App, Gmail, Amazon Simple Email Service (SES), Microsoft Office365 and many other SMTP (Simple Mail Transfer Protocol) servers
Stars: ✭ 281 (-66.35%)
Mutual labels:  transactional-emails, email, sendgrid
Sendgrid Java
The Official Twilio SendGrid Led, Community Driven Java API Library
Stars: ✭ 380 (-54.49%)
Mutual labels:  transactional-emails, email, sendgrid
Smartcode
SmartCode = IDataSource -> IBuildTask -> IOutput => Build Everything!!!
Stars: ✭ 464 (-44.43%)
Mutual labels:  dotnet-core, dotnetcore
Dotnet Win32 Service
Helper classes to set up and run as windows services directly on .net core. A ServiceBase alternative.
Stars: ✭ 425 (-49.1%)
Mutual labels:  dotnet-standard, dotnet-core

SendGrid Logo

BuildStatus NuGet Email Notifications Badge MIT licensed Twitter Follow GitHub contributors Open Source Helpers

Announcements

The default branch name for this repository has been changed to main as of 07/27/2020.

  • Subscribe to email notifications for releases and breaking changes.
  • Send SMS messages with Twilio.

Overview

This library allows you to quickly and easily use the Twilio SendGrid Web API v3 via C# with .NET.

Version 9.X.X+ of this library provides full support for all Twilio SendGrid Web API v3 endpoints, including the new v3 /mail/send.

We want this library to be community driven, and Twilio SendGrid led. We need your help to realize this goal. To help make sure we are building the right things in the right order, we ask that you create issues and pull requests or simply upvote or comment on existing issues or pull requests.

For updates to this library, see our CHANGELOG and releases.

Subscribe to email release notifications to receive emails about releases and breaking changes.

We appreciate your continued support, thank you!

Table of Contents

Installation

Prerequisites

  • .NET Framework 4.0+
  • .NET Core 1.0+
  • .NET Standard 1.3+
  • A Twilio SendGrid account, sign up for free to send up to 40,000 emails for the first 30 days, then send 100 emails/day free forever or check out our pricing.

Obtain an API Key

Grab your API Key from the Twilio SendGrid UI.

Setup Environment Variables to Manage Your API Key

Manage your Twilio SendGrid API Keys by storing them in Environment Variables or in Web.config. It is a good practice to keep your data and configuration settings separate. This way you can change your Twilio SendGrid API key without changing your code. Also, we strongly advise against storing sensitive data directly in your code.

Setup Environment Variables using the UI:

  1. Press Win+R and run SystemPropertiesAdvanced
  2. Click on Environment Variables
  3. Click New in user variables section
  4. Type SENDGRID_API_KEY in the name. (Make sure this name matches the name of the key in your code)
  5. Type actual API Key in the value
  6. Restart the IDE and you're done!

Setup Environment Variables using CMD:

  1. Run CMD as administrator
  2. set SENDGRID_API_KEY "YOUR_API_KEY"

Here are a few examples to get and set API Keys programmatically:

# Get Environment Variable
var apiKey = Environment.GetEnvironmentVariable("SENDGRID_API_KEY");

# Set Environment Variable
var setKey = Environment.SetEnvironmentVariable("SENDGRID_API_KEY", "YOUR_API_KEY");

Install Package

To use Twilio SendGrid in your C# project, you can either download the Twilio SendGrid C# .NET libraries directly from our Github repository or if you have the NuGet package manager installed, you can grab them automatically:

dotnet add package SendGrid

# use Twilio SendGrid with HttpClientFactory
dotnet add package SendGrid.Extensions.DependencyInjection

Once you have the Twilio SendGrid library installed, you can include calls to it in your code. For sample implementations, see the .NET Core Example and the .NET 4.5.2 Example folders.

Dependencies

Please see the .csproj file.

Quick Start

Hello Email

The following is the minimum needed code to send a simple email. Use this example, and modify the apiKey, from and to variables:

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

class Program
{
    static async Task Main()
    {
        var apiKey = Environment.GetEnvironmentVariable("SENDGRID_API_KEY");
        var client = new SendGridClient(apiKey);
        var from = new EmailAddress("[email protected]", "Example User");
        var subject = "Sending with Twilio SendGrid is Fun";
        var to = new EmailAddress("[email protected]", "Example User");
        var plainTextContent = "and easy to do anywhere, even with C#";
        var htmlContent = "<strong>and easy to do anywhere, even with C#</strong>";
        var msg = MailHelper.CreateSingleEmail(from, to, subject, plainTextContent, htmlContent);
        var response = await client.SendEmailAsync(msg).ConfigureAwait(false);
    }
}

After executing the above code, response.StatusCode should be 202 and you should have an email in the inbox of the to recipient. You can check the status of your email in the UI. Alternatively, we can post events to a URL of your choice using our Event Webhook. This gives you data about the events that occur as Twilio SendGrid processes your email.

For more advanced cases, you can build the SendGridMessage object yourself with these minimum required settings:

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

class Program
{
    static async Task Main()
    {
        var apiKey = Environment.GetEnvironmentVariable("SENDGRID_API_KEY");
        var client = new SendGridClient(apiKey);
        var msg = new SendGridMessage()
        {
            From = new EmailAddress("[email protected]", "DX Team"),
            Subject = "Sending with Twilio SendGrid is Fun",
            PlainTextContent = "and easy to do anywhere, even with C#",
            HtmlContent = "<strong>and easy to do anywhere, even with C#</strong>"
        };
        msg.AddTo(new EmailAddress("[email protected]", "Test User"));
        var response = await client.SendEmailAsync(msg).ConfigureAwait(false);
    }
}

You can find an example of all the email features here.

General v3 Web API Usage

using System;
using System.Threading.Tasks;
using SendGrid;

class Program
{
    static async Task Main()
    {
        var apiKey = Environment.GetEnvironmentVariable("SENDGRID_API_KEY");
        var client = new SendGridClient(apiKey);
        var queryParams = @"{'limit': 100}";
        var response = await client.RequestAsync(method: SendGridClient.Method.GET,urlPath: "suppression/bounces",
        queryParams: queryParams).ConfigureAwait(false);
    }
}

Web Proxy

var apiKey = Environment.GetEnvironmentVariable("SENDGRID_API_KEY");
var proxy = new WebProxy("http://proxy:1337");
var client = new SendGridClient(proxy, apiKey);

HttpClientFactory + Microsoft.Extensions.DependencyInjection

SendGrid.Extensions.DependencyInjection is required

using System;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using SendGrid;
using SendGrid.Extensions.DependencyInjection;
using SendGrid.Helpers.Mail;

class Program
{
    static async Task Main()
    {
        var services = ConfigureServices(new ServiceCollection()).BuildServiceProvider();
        var client = services.GetRequiredService<ISendGridClient>();
        var msg = new SendGridMessage()
        {
            From = new EmailAddress("[email protected]", "Example User"),
            Subject = "Sending with Twilio SendGrid is Fun"
        };
        msg.AddContent(MimeType.Text, "and easy to do anywhere, even with C#");
        msg.AddTo(new EmailAddress("[email protected]", "Example User"));
        var response = await client.SendEmailAsync(msg).ConfigureAwait(false);
    }

    private static IServiceCollection ConfigureServices(IServiceCollection services)
    {
        services.AddSendGrid(options =>
        {
            options.ApiKey = Environment.GetEnvironmentVariable("SENDGRID_API_KEY");
        });

        return services;
    }
}

Usage

Use Cases

Here are some examples of common API use cases, such as how to send an email with a transactional template.

How to Contribute

We encourage contribution to our library (you might even score some nifty swag), please see our CONTRIBUTING guide for details.

Quick links:

Troubleshooting

Please see our troubleshooting guide for common library issues.

About

sendgrid-csharp is maintained and funded by Twilio SendGrid, Inc. The names and logos for sendgrid-csharp are trademarks of Twilio SendGrid, Inc.

If you need help installing or using the library, please check the Twilio SendGrid Support Help Center.

If you've instead found a bug in the library or would like new features added, go ahead and open issues or pull requests against this repo!

License

The MIT License (MIT)

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].