{"id":13431567,"url":"https://github.com/sendgrid/sendgrid-csharp","last_synced_at":"2025-05-14T12:11:56.732Z","repository":{"id":2168422,"uuid":"3114746","full_name":"sendgrid/sendgrid-csharp","owner":"sendgrid","description":"The Official Twilio SendGrid C#, .NetStandard, .NetCore API Library","archived":false,"fork":false,"pushed_at":"2024-07-23T13:08:50.000Z","size":10195,"stargazers_count":1103,"open_issues_count":36,"forks_count":584,"subscribers_count":260,"default_branch":"main","last_synced_at":"2025-05-10T22:33:59.963Z","etag":null,"topics":["c-sharp","dotnet","dotnet-core","dotnet-standard","dotnetcore","email","sendgrid","transactional-emails"],"latest_commit_sha":null,"homepage":"https://sendgrid.com","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sendgrid.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2012-01-06T01:07:24.000Z","updated_at":"2025-05-09T21:32:45.000Z","dependencies_parsed_at":"2024-01-15T05:08:35.757Z","dependency_job_id":"9131f456-6faf-4ae0-b9b6-e9f8a1999ff5","html_url":"https://github.com/sendgrid/sendgrid-csharp","commit_stats":{"total_commits":1212,"total_committers":138,"mean_commits":8.782608695652174,"dds":0.7252475247524752,"last_synced_commit":"e66576c22174a9e6c0fee95459f5ae5db733ba25"},"previous_names":[],"tags_count":89,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sendgrid%2Fsendgrid-csharp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sendgrid%2Fsendgrid-csharp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sendgrid%2Fsendgrid-csharp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sendgrid%2Fsendgrid-csharp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sendgrid","download_url":"https://codeload.github.com/sendgrid/sendgrid-csharp/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254140768,"owners_count":22021220,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c-sharp","dotnet","dotnet-core","dotnet-standard","dotnetcore","email","sendgrid","transactional-emails"],"created_at":"2024-07-31T02:01:04.149Z","updated_at":"2025-05-14T12:11:56.689Z","avatar_url":"https://github.com/sendgrid.png","language":"C#","readme":"![SendGrid Logo](twilio_sendgrid_logo.png)\n\n[![Test and Deploy](https://github.com/sendgrid/sendgrid-csharp/actions/workflows/test-and-deploy.yml/badge.svg)](https://github.com/sendgrid/sendgrid-csharp/actions/workflows/test-and-deploy.yml)\n[![NuGet](https://img.shields.io/nuget/v/SendGrid.svg)](https://www.nuget.org/packages/SendGrid)\n[![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)\n[![Twitter Follow](https://img.shields.io/twitter/follow/sendgrid.svg?style=social\u0026label=Follow)](https://twitter.com/sendgrid)\n[![GitHub contributors](https://img.shields.io/github/contributors/sendgrid/sendgrid-csharp.svg)](https://github.com/sendgrid/sendgrid-csharp/graphs/contributors)\n[![Open Source Helpers](https://www.codetriage.com/sendgrid/sendgrid-csharp/badges/users.svg)](https://www.codetriage.com/sendgrid/sendgrid-csharp)\n\n# Announcements\n\n* Send SMS messages with [Twilio](USE_CASES.md#sms). \n\n# Overview\n\n**This library allows you to quickly and easily use the Twilio SendGrid Web API v3 via C# with .NET.**\n\nVersion 9.X.X+ of this library provides full support for all Twilio SendGrid [Web API v3](https://sendgrid.com/docs/API_Reference/api_v3.html) endpoints, including the new [v3 /mail/send](https://sendgrid.com/blog/introducing-v3mailsend-sendgrids-new-mail-endpoint).\n\nFor updates to this library, see our [CHANGELOG](CHANGELOG.md) and [releases](https://github.com/sendgrid/sendgrid-csharp/releases).\n\nWe appreciate your continued support, thank you!\n\n# Table of Contents\n\n* [Installation](#installation)\n  * [Prerequisites](#prerequisites)\n  * [Obtain an API Key](#obtain-api)\n  * [Setup Environment Variables to Manage Your API Key](#setup)\n  * [Install Package](#install-package)\n  * [Dependencies](#dependencies)\n* [Quick Start](#quick-start)\n  * [Hello Email](#hello)\n  * [General v3 Web API Usage](#v3)\n  * [Web Proxy](#proxy)\n* [Usage](#usage)\n* [Use Cases](#use-cases)\n* [Announcements](#announcements)\n* [How to Contribute](#how-to-contribute)\n* [Troubleshooting](#troubleshooting)\n* [About](#about)\n* [Support](#support)\n* [License](#license)\n\n# Installation\n\n## Prerequisites\n\n- .NET Framework 4.0+\n- .NET Core 1.0+\n- .NET Standard 1.3+\n- A Twilio SendGrid account, [sign up for free](https://sendgrid.com/free?source=sendgrid-csharp) to send up to 40,000 emails for the first 30 days, then send 100 emails/day free forever or check out [our pricing](https://sendgrid.com/pricing?source=sendgrid-csharp).\n\n\u003ca name=\"obtain-api\"\u003e\u003c/a\u003e\n## Obtain an API Key\n\nGrab your API Key from the [Twilio SendGrid UI](https://app.sendgrid.com/settings/api_keys).\n\n\u003ca name=\"setup\"\u003e\u003c/a\u003e\n## Setup Environment Variables to Manage Your API Key\n\nManage your [Twilio SendGrid API Keys](https://app.sendgrid.com/settings/api_keys) by storing them in Environment Variables or in [Web.config](https://docs.microsoft.com/en-us/aspnet/identity/overview/features-api/best-practices-for-deploying-passwords-and-other-sensitive-data-to-aspnet-and-azure). 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.\n\nSetup Environment Variables using the UI:\n\n1. Press Win+R and run SystemPropertiesAdvanced\n2. Click on Environment Variables\n3. Click New in user variables section\n4. Type SENDGRID_API_KEY in the name. (Make sure this name matches the name of the key in your code)\n5. Type actual API Key in the value\n6. Restart the IDE and you're done!\n\nSetup Environment Variables using CMD:\n\n1. Run CMD as administrator\n2. set SENDGRID_API_KEY=\"YOUR_API_KEY\"\n\nHere are a few examples to get and set API Keys programmatically:\n\n```csharp\n# Get Environment Variable\nvar apiKey = Environment.GetEnvironmentVariable(\"SENDGRID_API_KEY\");\n\n# Set Environment Variable\nvar setKey = Environment.SetEnvironmentVariable(\"SENDGRID_API_KEY\", \"YOUR_API_KEY\");\n```\n\n## Install Package\n\nTo use Twilio SendGrid in your C# project, you can either \u003ca href=\"https://github.com/sendgrid/sendgrid-csharp.git\"\u003edownload the Twilio SendGrid C# .NET libraries directly from our Github repository\u003c/a\u003e or if you have the NuGet package manager installed, you can grab them automatically:\n\n```sh\ndotnet add package SendGrid\n\n# use Twilio SendGrid with HttpClientFactory\ndotnet add package SendGrid.Extensions.DependencyInjection\n```\n\nOnce you have the Twilio SendGrid library installed, you can include calls to it in your code.\nFor sample implementations, see the [.NET Core Example](ExampleCoreProject) and the [.NET 4.5.2 Example](ExampleNet45Project) folders.\n\n## Dependencies\n\nPlease see the [.csproj file](src/SendGrid/SendGrid.csproj).\n\n# Quick Start\n\n\u003ca name=\"hello\"\u003e\u003c/a\u003e\n## Hello Email\n\nThe following is the minimum needed code to send a simple email. Use this example, and modify the `apiKey`, `from` and `to` variables:\n\n```csharp\nusing System;\nusing System.Threading.Tasks;\nusing SendGrid;\nusing SendGrid.Helpers.Mail;\n\nclass Program\n{\n    static async Task Main()\n    {\n        var apiKey = Environment.GetEnvironmentVariable(\"SENDGRID_API_KEY\");\n        var client = new SendGridClient(apiKey);\n        var from = new EmailAddress(\"test@example.com\", \"Example User\");\n        var subject = \"Sending with Twilio SendGrid is Fun\";\n        var to = new EmailAddress(\"test@example.com\", \"Example User\");\n        var plainTextContent = \"and easy to do anywhere, even with C#\";\n        var htmlContent = \"\u003cstrong\u003eand easy to do anywhere, even with C#\u003c/strong\u003e\";\n        var msg = MailHelper.CreateSingleEmail(from, to, subject, plainTextContent, htmlContent);\n        var response = await client.SendEmailAsync(msg).ConfigureAwait(false);\n    }\n}\n```\n\nAfter 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](https://app.sendgrid.com/email_activity?). Alternatively, we can post events to a URL of your choice using our [Event Webhook](https://docs.sendgrid.com/for-developers/tracking-events/getting-started-event-webhook). This gives you data about the events that occur as Twilio SendGrid processes your email.\n\nFor more advanced cases, you can build the SendGridMessage object yourself with these minimum required settings:\n\n```csharp\nusing System;\nusing System.Threading.Tasks;\nusing SendGrid;\nusing SendGrid.Helpers.Mail;\n\nclass Program\n{\n    static async Task Main()\n    {\n        var apiKey = Environment.GetEnvironmentVariable(\"SENDGRID_API_KEY\");\n        var client = new SendGridClient(apiKey);\n        var msg = new SendGridMessage()\n        {\n            From = new EmailAddress(\"test@example.com\", \"DX Team\"),\n            Subject = \"Sending with Twilio SendGrid is Fun\",\n            PlainTextContent = \"and easy to do anywhere, even with C#\",\n            HtmlContent = \"\u003cstrong\u003eand easy to do anywhere, even with C#\u003c/strong\u003e\"\n        };\n        msg.AddTo(new EmailAddress(\"test@example.com\", \"Test User\"));\n        var response = await client.SendEmailAsync(msg).ConfigureAwait(false);\n    }\n}\n```\n\nYou can find an example of all the email features [here](tests/SendGrid.Tests/Integration.cs#L79).\n\n\u003ca name=\"v3\"\u003e\u003c/a\u003e\n## General v3 Web API Usage\n\n```csharp\nusing System;\nusing System.Threading.Tasks;\nusing SendGrid;\n\nclass Program\n{\n    static async Task Main()\n    {\n        var apiKey = Environment.GetEnvironmentVariable(\"SENDGRID_API_KEY\");\n        var client = new SendGridClient(apiKey);\n        var queryParams = @\"{'limit': 100}\";\n        var response = await client.RequestAsync(method: SendGridClient.Method.GET,urlPath: \"suppression/bounces\",\n        queryParams: queryParams).ConfigureAwait(false);\n    }\n}\n```\n\n## HttpClientFactory + Microsoft.Extensions.DependencyInjection\n\n\u003e [SendGrid.Extensions.DependencyInjection](https://www.nuget.org/packages/SendGrid.Extensions.DependencyInjection) is required\n\n```csharp\nusing System;\nusing System.Threading.Tasks;\nusing Microsoft.Extensions.DependencyInjection;\nusing SendGrid;\nusing SendGrid.Extensions.DependencyInjection;\nusing SendGrid.Helpers.Mail;\n\nclass Program\n{\n    static async Task Main()\n    {\n        var services = ConfigureServices(new ServiceCollection()).BuildServiceProvider();\n        var client = services.GetRequiredService\u003cISendGridClient\u003e();\n        var msg = new SendGridMessage()\n        {\n            From = new EmailAddress(\"test@example.com\", \"Example User\"),\n            Subject = \"Sending with Twilio SendGrid is Fun\"\n        };\n        msg.AddContent(MimeType.Text, \"and easy to do anywhere, even with C#\");\n        msg.AddTo(new EmailAddress(\"test@example.com\", \"Example User\"));\n        var response = await client.SendEmailAsync(msg).ConfigureAwait(false);\n    }\n\n    private static IServiceCollection ConfigureServices(IServiceCollection services)\n    {\n        services.AddSendGrid(options =\u003e\n        {\n            options.ApiKey = Environment.GetEnvironmentVariable(\"SENDGRID_API_KEY\");\n        });\n\n        return services;\n    }\n}\n```\n\n\u003ca name=\"proxy\"\u003e\u003c/a\u003e\n## Web Proxy\n\n```csharp\nvar apiKey = Environment.GetEnvironmentVariable(\"SENDGRID_API_KEY\");\nvar proxy = new WebProxy(\"http://proxy:1337\");\nvar client = new SendGridClient(proxy, apiKey);\n```\n\nOr when using DependencyInjection\n\n```csharp\nservices.AddSendGrid(options =\u003e\n{\n    options.ApiKey = Environment.GetEnvironmentVariable(\"SENDGRID_API_KEY\");\n})\n.ConfigurePrimaryHttpMessageHandler(_ =\u003e new HttpClientHandler()\n{\n    Proxy = new WebProxy(new Uri(\"http://proxy:1337\")),\n    UseProxy = true\n});\n```\n\n\n# Usage\n\n- [Twilio SendGrid Docs](https://docs.sendgrid.com/api-reference/)\n- [Library Usage Docs](USAGE.md)\n- [Example Code - .NET Core](ExampleCoreProject)\n- [Example Code - .NET 4.5.2+](ExampleNet45Project)\n- [How-to: Migration from v2 to v3](https://sendgrid.com/docs/Classroom/Send/v3_Mail_Send/how_to_migrate_from_v2_to_v3_mail_send.html)\n- [v3 Web API Mail Send Helper](src/SendGrid/Helpers/Mail)\n\n# Use Cases\n\nHere are some [examples of common API use cases](USE_CASES.md), such as how to send an email with a transactional template.\n\n# How to Contribute\n\nWe encourage contribution to our library (you might even score some nifty swag), please see our [CONTRIBUTING](CONTRIBUTING.md) guide for details.\n\nQuick links:\n\n- [Feature Request](CONTRIBUTING.md#feature-request)\n- [Bug Reports](CONTRIBUTING.md#submit-a-bug-report)\n- [Improvements to the Codebase](CONTRIBUTING.md#improvements-to-the-codebase)\n- [Review Pull Requests](CONTRIBUTING.md#code-reviews)\n\n# Troubleshooting\n\nPlease see our [troubleshooting guide](TROUBLESHOOTING.md) for common library issues.\n\n# About\n\nsendgrid-csharp is maintained and funded by Twilio SendGrid, Inc. The names and logos for sendgrid-csharp are trademarks of Twilio SendGrid, Inc.\n\n# Support\n\nIf you need help using SendGrid, please check the [Twilio SendGrid Support Help Center](https://support.sendgrid.com).\n\n# License\n[The MIT License (MIT)](LICENSE)\n","funding_links":[],"categories":["Frameworks, Libraries and Tools","dotnet","C# #","C#","Libraries","SDKs","框架, 库和工具"],"sub_categories":["SDKs","Mail and SMTP Server","开发工具包SDKs"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsendgrid%2Fsendgrid-csharp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsendgrid%2Fsendgrid-csharp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsendgrid%2Fsendgrid-csharp/lists"}