{"id":13735055,"url":"https://github.com/sendgrid/smtpapi-csharp","last_synced_at":"2025-09-05T16:26:33.049Z","repository":{"id":12942017,"uuid":"15619935","full_name":"sendgrid/smtpapi-csharp","owner":"sendgrid","description":"SendGrid's smtpapi library in C#","archived":false,"fork":false,"pushed_at":"2023-04-10T00:18:16.000Z","size":2951,"stargazers_count":27,"open_issues_count":0,"forks_count":60,"subscribers_count":202,"default_branch":"main","last_synced_at":"2024-08-03T03:04:21.541Z","etag":null,"topics":[],"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}},"created_at":"2014-01-03T21:26:42.000Z","updated_at":"2024-08-03T03:04:21.542Z","dependencies_parsed_at":"2024-01-12T01:15:03.226Z","dependency_job_id":"e25733cb-f84b-4167-84a9-7e3bd255d4a9","html_url":"https://github.com/sendgrid/smtpapi-csharp","commit_stats":null,"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sendgrid%2Fsmtpapi-csharp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sendgrid%2Fsmtpapi-csharp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sendgrid%2Fsmtpapi-csharp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sendgrid%2Fsmtpapi-csharp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sendgrid","download_url":"https://codeload.github.com/sendgrid/smtpapi-csharp/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224727173,"owners_count":17359532,"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":[],"created_at":"2024-08-03T03:01:02.568Z","updated_at":"2024-11-15T03:31:22.540Z","avatar_url":"https://github.com/sendgrid.png","language":"C#","funding_links":[],"categories":["Libraries"],"sub_categories":["Mail and SMTP Server"],"readme":"![SendGrid Logo](twilio_sendgrid_logo.png)\n\n[![Test and Deploy](https://github.com/sendgrid/smtpapi-csharp/actions/workflows/test-and-deploy.yml/badge.svg)](https://github.com/sendgrid/smtpapi-csharp/actions/workflows/test-and-deploy.yml)\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/smtpapi-csharp.svg)](https://github.com/sendgrid/smtpapi-csharp/graphs/contributors)\n[![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)\n\n**This module helps build SendGrid's SMTP API headers.**\n\n# Announcements\nAll updates to this module are documented in our [CHANGELOG](CHANGELOG.md).\n\n# Table of Contents\n- [Installation](#installation)\n- [Quick Start](#quick-start)\n- [Usage](#usage)\n- [How to Contribute](#contribute)\n- [About](#about)\n- [Support](#support)\n- [License](#license)\n\n\u003ca name=\"installation\"\u003e\u003c/a\u003e\n# Installation\n\n## Prerequisites\n\n- .NET Framework 4.0+\n- [The SendGrid service](https://sendgrid.com/free?source=smtpapi-csharp)\n\n## Setup Environment Variables\n\n### Environment Variable\n\nUpdate the development environment with your [SENDGRID_API_KEY](https://app.sendgrid.com/settings/api_keys), for example:\n\n1. Make a copy of the .env_sample file and name it .env\n2. Edit the file changing only the value of SENDGRID_PASSWORD variable\n3. Save the file\n4. Add the .env file to your environment path\n\n## Install Package\n\nTo use SendGrid.SmtpApi in your C# project, you can either \u003ca href=\"https://github.com/sendgrid/smtpapi-csharp.git\"\u003edownload the 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```bash\nPM\u003e Install-Package SendGrid.SmtpApi\n```\n\nOnce you have the library properly referenced in your project, you can include calls to them in your code.\n\nFor a sample implementation, check the [Example](Smtpapi/Example/Program.cs)\n\n\u003ca name=\"quick-start\"\u003e\u003c/a\u003e\n# Quick Start\n\n```csharp\nvar header = new Header();\n\nvar uniqueArgs = new Dictionary\u003cstring,string\u003e {\n  { \"foo\", \"bar\" },\n  { \"chunky\", \"bacon\"}\n};\n\nheader.AddUniqueArgs(uniqueArgs);\n\nvar xmstpapiJson = header.JsonString();\n```\nYou can then use the generated JSON in conjunction with your favorite SMTP library.\n\n```csharp\nSmtpClient client = new SmtpClient();\nclient.Port = 587;\nclient.Host = \"smtp.sendgrid.net\";\nclient.Timeout = 10000;\nclient.DeliveryMethod = SmtpDeliveryMethod.Network;\nclient.UseDefaultCredentials = false;\nclient.Credentials = new System.Net.NetworkCredential(\"your_sendgrid_username\",\"your_sendgrid_password\");\n\nMailMessage mail = new MailMessage();\nmail.To.Add(new MailAddress(\"user@example.com\"));\nmail.From = new MailAddress(\"you@yourcompany.com\");\nmail.Subject = \"this is a test email.\";\nmail.Body = \"this is my test email body\";\n\n// add the custom header that we built above\nmail.Headers.Add( \"X-SMTPAPI\", xmstpapiJson );\n\nclient.SendAsync(mail, null);\n```\n\nIf you want to add multiple recipients to the X-SMTPAPI header for a mail merge type send, you can do something like the following:\n\n```csharp\nvar header = new Header();\n\nvar recipients = new List\u003cString\u003e {\"test1@example.com\", \"test2@example.com\", \"test3@example.com\"};\nheader.SetTo(recipients);\n\nvar subs = new List\u003cString\u003e {\"A\",\"B\",\"C\"};\nheader.AddSubstitution(\"%name%\", subs);\n\nvar mail = new MailMessage\n{\n    From = new MailAddress(\"test@example.com\"),\n    Subject = \"Welcome\",\n    Body = \"Hi there %name%\"\n};\n\n// add the custom header that we built above\nmail.Headers.Add(\"X-SMTPAPI\", header.JsonString());\n```\n\n\u003ca name=\"usage\"\u003e\u003c/a\u003e\n# Usage\n\n- [SendGrid Docs](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html)\n- [Example Code](Smtpapi/Example/Program.cs)\n\n\u003ca name=\"contribute\"\u003e\u003c/a\u003e\n# How to Contribute\n\nWe encourage contribution to our projects, please see our [CONTRIBUTING](CONTRIBUTING.md) guide for details.\n\nQuick links:\n\n- [Feature Request](CONTRIBUTING.md)\n- [Bug Reports](CONTRIBUTING.md#submit-a-bug-report)\n- [Improvements to the Codebase](CONTRIBUTING.md#improvements-to-the-codebase)\n\n\u003ca name=\"about\"\u003e\u003c/a\u003e\n# About\n\nsmtpapi-csharp is maintained and funded by Twilio SendGrid, Inc. The names and logos for smtpapi-csharp are trademarks of Twilio SendGrid, Inc.\n\n\u003ca name=\"support\"\u003e\u003c/a\u003e\n# Support\n\nIf you need help using SendGrid, please check the [Twilio SendGrid Support Help Center](https://support.sendgrid.com).\n\n\u003ca name=\"license\"\u003e\u003c/a\u003e\n# License\n[The MIT License (MIT)](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsendgrid%2Fsmtpapi-csharp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsendgrid%2Fsmtpapi-csharp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsendgrid%2Fsmtpapi-csharp/lists"}