{"id":21105289,"url":"https://github.com/aristurtledev/smtpkit","last_synced_at":"2025-08-05T04:27:38.588Z","repository":{"id":63317531,"uuid":"566900049","full_name":"AristurtleDev/SmtpKit","owner":"AristurtleDev","description":"A small .NET library for sending emails using SMTP.","archived":false,"fork":false,"pushed_at":"2022-11-18T20:32:15.000Z","size":232,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-08-01T01:58:02.300Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/AristurtleDev.png","metadata":{"files":{"readme":"README.md","changelog":null,"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}},"created_at":"2022-11-16T16:46:15.000Z","updated_at":"2025-01-28T07:28:06.000Z","dependencies_parsed_at":"2023-01-21T23:51:58.248Z","dependency_job_id":null,"html_url":"https://github.com/AristurtleDev/SmtpKit","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/AristurtleDev/SmtpKit","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AristurtleDev%2FSmtpKit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AristurtleDev%2FSmtpKit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AristurtleDev%2FSmtpKit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AristurtleDev%2FSmtpKit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AristurtleDev","download_url":"https://codeload.github.com/AristurtleDev/SmtpKit/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AristurtleDev%2FSmtpKit/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268835097,"owners_count":24314941,"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","status":"online","status_checked_at":"2025-08-05T02:00:12.334Z","response_time":2576,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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-11-20T00:05:03.609Z","updated_at":"2025-08-05T04:27:38.564Z","avatar_url":"https://github.com/AristurtleDev.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003e\n\u003cimg src=\"https://raw.githubusercontent.com/AristurtleDev/SmtpKit/main/.github/images/smtpkit-banner.png\" alt=\"SmtpKit Logo\"\u003e\n\u003cbr/\u003e\nA Small .NET Library For Sending Emails Using SMTP\n\u003c/h1\u003e\n\nSmtpKit is a small .NET library for sending emails using SMTP, featuring a fluent syntax for creating and sending the email messages.  Can be used both with and without dependency injection.\n\n## Basic Usage (Without Dependency Injection)\n\n```csharp\n//  Create a sender\nIEmailSender sender = new SmtpSender(\"host\", 25);\n\n//  Create and send email\nEmail.Create(\"from@address.com\", smtp)\n     .To(\"to@address.com\")\n     .Subject(\"Hello World\")\n     .PlainTextBody(\"How are you today?\")\n     .HtmlBody(\"\u003cp\u003eHow are you today?\u003c/p\u003e\")\n     .Send();\n```\n\nEach email created must be given an **email address** that the email is from and an `IEmailSender` instance which is used to perform the delivery of the email.  In the example above, we are using an instance of the `SmtpSender` which will send the email message to an SMTP sever for delivery.  There may be times, however, when this is not ideal.  For instance, if you are on a local development environment which doesn't have access to communicate with the SMTP server.  In those instance, two other `IEmailSender` implementations are available. \n\n| Name | Description | Example Usage |\n| ---- | ----------- | ------------- |\n| `ConsoleSender` | Writes the contents of the email message built to the console window | `IEmailSender sender = new Console()` |\n| `FileSystemSender` | Writes the contents of the email message to a text file in a specified directory | `IEmailSender sender = new FileSystemSender(\"path/to/output/directory\")` |\n\n\u003cbr /\u003e\n\n\u003e 💡 **Note**:  \n\u003e After calling `Send()`, the `IEmail` instance that is created will internally dispose of itself after the message is sent.  This is to release any resources that are being held by attachments added to the email.\n\n\n## Dependency Injection\nSmtpKit comes with extension methods to easily add it as a dependency in your service container for dependency injection.  By doing this, it will inject an instance of `IEmailFactory` which can be used each time you need to create and send an email message.  The following example demonstrates how to add it to your services container\n\n```csharp\nservices.AddSmtpKit(\"from@address.com\")\n        .UseSmtp(\"host\", 25);\n```\n\nThe example above shows how to add it to your services container using SMTP as the delivery method.  Just like it was mentioned in the [Basic Usage](#basic-usage-without-dependency-injection) section above, there may be times when you are developing but can't connect to your SMTP server.  In these situations, you can tell the service to use a `ConsoleSender` or `FileSystemSender` by calling the appropriate `UseConsole()` or `UseFileSystem(string)` methods instead of `UseSmtp(string, int)`.\n\n\u003cbr /\u003e\n\n\u003e 💡 **Note**:  \n\u003e You can only specify to use one of smtp, console, or file system for the service added.\n\n\nAfter adding it to your services container, in your code where the `IEmailFactory` instance will be injected (e.g. Razor PageModel), you call the `Create()` method from the `IEmailFactory` instance to create the email instance, which you can then use the fluent syntax to create and send it.  The following is an example of this in a Razor PageModel:\n\n```csharp\npublic class MyPageModel : PageModel\n{\n    private readonly IEmailFactory _factory;\n\n    //  IEmailFactory supplied by dependency injection\n    public class MyPageModel(IEmailFactory factory) =\u003e _factory = factory;\n\n    public async Task OnPostAsync()\n    {\n        await factory.Create()\n                     .To(\"other@address.com\", \"Other Person\")\n                     .Subject(\"Hello World\")\n                     .PlainTextBody(\"How are you today?\")\n                     .HtmlBody(\"\u003cp\u003eHow are you today?\u003c/p\u003e\")\n                     .SendAsync();        \n    }\n```\n\n## Using Templates (Experimental)\nTemplates are currently supported in code but are marked as an experimental feature.  Using templates is a great way to keep your code files clean and make the email templates reusable and dynamic with variables. \n\n**Template variables** are sections within your template file that are wrapped in double curly brackets.  For instance, consider the following template\n\n```plaintext\nHello {{Name}},\nToday is {{CurrentDate}}\n```\n\nWhen using a template, a model `class` instance must be given.  Any **public** properties of that class that have a name that matches the name of the **template variable** will have that property value injected into the template.  For example, if I had the following model:\n\n```csharp\npublic class TemplateModel\n{\n    public string Name { get; set; }\n    public DateTime DateTime { get; set; }\n}\n```\n\nThe value of the property `TemplateModel.Name` would be injected anywhere in the template where `{{Name}}` appeared,and the value fo the property `TemplateModel.CurrentDate` would be injected anywhere in the template where `{{CurrentDate}}` appeared.\n\nTo make use of a template, you use the `.PlainTextBody\u003cT\u003e(string, T?)` or `.HtmlBody\u003cT\u003e(string, T?)` methods like in the following example\n\n```csharp\nEmail.Create(\"from@address.com\", smtp)\n     .To(\"to@address.com\")\n     .Subject(\"Hello World\")\n     .PlainTextBody\u003cTemplateModel\u003e(\"path/to/template/file\", templateInstance)\n     .HtmlBody\u003cTemplateModel\u003e(\"path/to/template/file\", templateInstance)\n     .Send();\n```\n\n## License\n**SmtpKit** is licensed under the **MIT License**.  Please refer to the [LICENSE](LICENSE) file for full license text.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faristurtledev%2Fsmtpkit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faristurtledev%2Fsmtpkit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faristurtledev%2Fsmtpkit/lists"}