{"id":13430900,"url":"https://github.com/doxakis/MailBody","last_synced_at":"2025-03-16T06:31:35.250Z","repository":{"id":60773994,"uuid":"71683850","full_name":"doxakis/MailBody","owner":"doxakis","description":"Create transactional email with a fluent interface (.net)","archived":false,"fork":false,"pushed_at":"2024-06-21T15:03:16.000Z","size":193,"stargazers_count":159,"open_issues_count":1,"forks_count":13,"subscribers_count":10,"default_branch":"master","last_synced_at":"2024-09-26T02:40:38.909Z","etag":null,"topics":["csharp","dotnet","dotnetcore","email","fluent-interface"],"latest_commit_sha":null,"homepage":"https://doxakis.github.io/MailBody/","language":"HTML","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/doxakis.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2016-10-23T05:32:30.000Z","updated_at":"2024-09-18T17:53:02.000Z","dependencies_parsed_at":"2024-01-05T20:52:24.364Z","dependency_job_id":"4e20b247-5e5e-473b-b54d-74cb0e1e98ee","html_url":"https://github.com/doxakis/MailBody","commit_stats":{"total_commits":42,"total_committers":5,"mean_commits":8.4,"dds":"0.33333333333333337","last_synced_commit":"730abf4df8ecb0b1ea50db3d74d155c7a7cd4e8c"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/doxakis%2FMailBody","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/doxakis%2FMailBody/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/doxakis%2FMailBody/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/doxakis%2FMailBody/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/doxakis","download_url":"https://codeload.github.com/doxakis/MailBody/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221656466,"owners_count":16858777,"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":["csharp","dotnet","dotnetcore","email","fluent-interface"],"created_at":"2024-07-31T02:00:58.836Z","updated_at":"2024-10-27T09:31:04.483Z","avatar_url":"https://github.com/doxakis.png","language":"HTML","readme":"# MailBody [![NuGet Status](https://badge.fury.io/nu/mailbody.svg)](https://www.nuget.org/packages/MailBody)\nMailBody is a library for generating transactional email by using a fluent interface.\n\nThe current mail template is based on https://github.com/leemunroe/responsive-html-email-template\n(MIT License 2013 Lee Munroe)\n\n# Supported framework\n- .net standard 2.0 (so, both .net core and .net framework)\n\n# Install from Nuget\nTo get the latest version:\n```\nInstall-Package MailBody\n```\n\n# MailBody Editor\nIf you want to create email with the MailBody library while having a live preview, you can use the [MailBody Editor](https://github.com/doxakis/MailBodyEditor)\n\u003cp align=\"center\"\u003e\n    \u003cimg alt=\"Preview\" src=\"Preview.png\" /\u003e\n\u003c/p\u003e\n\n# Quick Examples\n\n## Email Address Confirmation\n\n### C# syntax:\n```\nvar body = MailBody\n    .CreateBody()\n    .Paragraph(\"Please confirm your email address by clicking the link below.\")\n    .Paragraph(\"We may need to send you critical information about our service and it is important that we have an accurate email address.\")\n    .Button(\"https://example.com/\", \"Confirm Email Address\")\n    .Paragraph(\"— [Insert company name here]\")\n    .ToString();\n```\n\n### Visual Basic syntax:\n```\nDim body As String = MailBody.CreateBody() _\n    .Paragraph(\"Please confirm your email address by clicking the link below.\") _\n    .Paragraph(\"We may need to send you critical information about our service and it is important that we have an accurate email address.\") _\n    .Button(\"https://example.com/\", \"Confirm Email Address\") _\n    .Paragraph(\"— [Insert company name here]\") _\n    .ToString()\n```\n[Preview](https://doxakis.github.io/MailBody/src/Example/Output/EmailAddressConfirmation.html)\n\n## Password reset\n```\nvar appName = \"My app\";\n\nvar body = MailBody\n    .CreateBody()\n    .Paragraph(\"Hi,\")\n    .Paragraph(\"You're receiving this email because someone requested a password reset for your user account at \" + appName + \".\")\n    .Button(\"https://www.example.com/\", \"Reset password\")\n    .Paragraph(\"Thanks for using \" + appName + \"!\")\n    .Paragraph(\"— [Insert company name here]\")\n    .ToString();\n```\n\n[Preview](https://doxakis.github.io/MailBody/src/Example/Output/PasswordReset.html)\n\n## Order confirmation\n```\nvar products = new string[] { \"1 x Product A\", \"2 x Product B\", \"3 x Product C\" };\n\n// Format product display.\nvar items = products.Select(item =\u003e MailBody.CreateBlock().Text(item));\n            \nvar body = MailBody\n    .CreateBody()\n    .Title(\"Confirmation of your order\")\n    .Paragraph(\"Hello,\")\n    .Paragraph(\"We confirm having received your order.\")\n    .Paragraph(\"Here is the list of ordered items:\")\n    .UnorderedList(items)\n    .Paragraph(\"Thank you for ordering from us!\")\n    .Paragraph(\"— [Insert company name here]\")\n    .ToString();\n```\n\n[Preview](https://doxakis.github.io/MailBody/src/Example/Output/OrderConfirmation.html)\n\n## Notification\n```\nvar productName = \"ABC\";\nvar productStatus = \"available\";\nvar productDescription = \"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla sagittis nisl ut tellus egestas facilisis. Nulla eget erat dictum, facilisis libero sit amet, sollicitudin tortor. Morbi iaculis, urna eu tincidunt dapibus, sapien ex dictum nibh, non congue urna tellus vitae risus.\";\nvar components = new string[] { \"Part A\", \"Part B\" };\n            \n// Format product display.\nvar items = components.Select(item =\u003e MailBody.CreateBlock().Text(item));\n            \nvar body = MailBody\n    .CreateBody()\n    .Paragraph(\"Hello,\")\n    .Paragraph(\"The product \" + productName + \" is now \" + productStatus + \".\")\n    .SubTitle(\"Here is the product summary:\")\n    .Paragraph(MailBody.CreateBlock()\n        .StrongText(\"Product name: \").Text(productName))\n    .Paragraph(MailBody.CreateBlock()\n        .StrongText(\"Description: \").Text(productDescription))\n    .Paragraph(MailBody.CreateBlock()\n        .StrongText(\"Components:\"))\n    .UnorderedList(items)\n    .Paragraph(\"— [Insert company name here]\")\n    .ToString();\n```\n\n[Preview](https://doxakis.github.io/MailBody/src/Example/Output/Notification.html)\n\n## With footer\n```\nvar footer = MailBody\n    .CreateBlock()\n    .Text(\"Follow \")\n    .Link(\"http://twitter.com/example\", \"@Example\")\n    .Text(\" on Twitter.\");\n\nvar body = MailBody\n    .CreateBody(footer)\n    .Paragraph(\"Please confirm your email address by clicking the link below.\")\n    .Paragraph(\"We may need to send you critical information about our service and it is important that we have an accurate email address.\")\n    .Button(\"https://www.example.com/\", \"Confirm Email Address\")\n    .Paragraph(\"— [Insert company name here]\")\n    .ToString();\n```\n\n[Preview](https://doxakis.github.io/MailBody/src/Example/Output/Withfooter.html)\n\n## With image\n**Please note** You can use CID Embedded Images, Base64 Encoding or use absolute url.\nImage may not appear on all email client. So, make sure to do some tests.\n\n```\nvar body = MailBody\n    .CreateBody()\n    .Image(\"https://placehold.it/540x70/ffffff/e8117f?text=My+logo\", \"My company name\")\n    .Paragraph(\"Please confirm your email address by clicking the link below.\")\n    .Paragraph(\"We may need to send you critical information about our service and it is important that we have an accurate email address.\")\n    .Button(\"https://example.com/\", \"Confirm Email Address\")\n    .Paragraph(\"— [Insert company name here]\")\n    .ToString();\n```\n\n[Preview](https://doxakis.github.io/MailBody/src/Example/Output/WithImage.html)\n\n## Custom theme \u0026 Raw html\n```\nvar template = MailBodyTemplate.GetDefaultTemplate();\ntemplate\n    .Paragraph(m =\u003e \"\u003cp style='\" +\n        (m.TryGetAttribute(\"color\", out string color) ? $\"color:{color};\" : string.Empty) +\n        (m.TryGetAttribute(\"backgroundColor\", out string backgroundColor) ? $\"background-color:{backgroundColor};\" : string.Empty) +\n        $\"'\u003e{m.Content}\u003c/p\u003e\")\n    .Body(m =\u003e \"\u003chtml\u003e\u003cbody\u003e\" + m.Content + \"\u003cbr /\u003e\" + m.Footer + \"\u003c/body\u003e\u003c/html\u003e\")\n    .Text(m =\u003e\n        \"\u003cspan style='\" + (m.HasAttribute(\"color\") ? $\"color:{m.GetAttribute(\"color\")};\" : string.Empty) +\n        (m.HasAttribute(\"backgroundColor\") ? $\"background-color:{m.GetAttribute(\"backgroundColor\")};\" : string.Empty) +\n        (m.HasAttribute(\"fontWeight\") ? $\"font-weight:{m.GetAttribute(\"fontWeight\")};\" : string.Empty) +\n        $\"'\u003e{m.Content}\u003c/span\u003e\");\n\nvar footer = MailBody\n    .CreateBlock()\n    .Text(\"Follow \", new { color = \"red\"})\n    .Link(\"http://twitter.com/example\", \"@Example\")\n    .Text(\" on Twitter.\", new { color = \"#009900\", backgroundColor = \"#CCCCCC\", fontWeight = \"bold\" });\n            \nvar body = MailBody\n    .CreateBody(template, footer)\n    .Paragraph(\"Please confirm your email address by clicking the link below.\")\n    .Raw(\"\u003cp\u003eWe may need to send you \u003cstrong\u003ecritical information\u003c/strong\u003e about our service and it is important that we have an accurate email address.\u003c/p\u003e\")\n    .Button(\"https://www.example.com/\", \"Confirm Email Address\")\n    .Paragraph(\"— [Insert company name here]\", new { color = \"white\", backgroundColor = \"black\" })\n    .ToString();\n```\n\n[Preview](https://doxakis.github.io/MailBody/src/Example/Output/CustomThemeAndRawHtml.html)\n\n## Another way to create your email\n```\nvar body = MailBody.CreateBody();\n\nbody.Paragraph(\"Hi,\")\n    .Paragraph(\"First paragraph..\");\n\n// Your code\n\nbody.Button(\"https://www.example.com/\", \"First button\");\nbody.Paragraph(\"Another paragraph..\");\n\n// Your code\n\nbody.Button(\"https://www.example.com/\", \"Second button\")\n    .Paragraph(\"— [Insert company name here]\");\n\nvar htmlBody = body.ToString();\n```\n\n[Preview](https://doxakis.github.io/MailBody/src/Example/Output/AnotherWay.html)\n\n## Override the default template\nThis example is based on [Postmark templates](https://github.com/wildbit/postmark-templates).\n\n```\nvar template = MailBodyTemplate.GetDefaultTemplate()\n    .Paragraph(m =\u003e $\"\u003cp style='font-family: sans-serif; font-size: 14px; font-weight: normal; margin: 0; Margin-bottom: 15px;'\u003e{m.Content}\u003c/p\u003e\")\n    .Link(m =\u003e $\"\u003ca href='{m.Link}'\u003e{m.Content}\u003c/a\u003e\")\n    .Title(m =\u003e $\"\u003ch1\u003e{m.Content}\u003c/h1\u003e\")\n    .SubTitle(m =\u003e $\"\u003ch2\u003e{m.Content}\u003c/h2\u003e\")\n    .Text(m =\u003e $\"{m.Content}\")\n    .StrongText(m =\u003e $\"\u003cstrong\u003e{m.Content}\u003c/strong\u003e\")\n    .UnorderedList(m =\u003e $\"\u003cul\u003e{m.Content}\u003c/ul\u003e\")\n    .OrderedList(m =\u003e $\"\u003col\u003e{m.Content}\u003c/ol\u003e\")\n    .ListItem(m =\u003e $\"\u003cli\u003e{m.Content}\u003c/li\u003e\")\n    .LineBreak(m =\u003e $\"\u003c/br\u003e\")\n    .Button(m =\u003e @\"\u003ctable class='body-action' align='center' width='100%' cellpadding='0' cellspacing='0'\u003e\n            \u003ctr\u003e\n                \u003ctd align='center'\u003e\n                \u003ctable width='100%' border='0' cellspacing='0' cellpadding='0'\u003e\n                    \u003ctr\u003e\n                    \u003ctd align='center'\u003e\n                        \u003ctable border='0' cellspacing='0' cellpadding='0'\u003e\n                        \u003ctr\u003e\n                            \u003ctd\u003e\n                            \u003ca href='\" + m.Link + @\"' class='button button--' target='_blank'\u003e\" + m.Content + @\"\u003c/a\u003e\n                            \u003c/td\u003e\n                        \u003c/tr\u003e\n                        \u003c/table\u003e\n                    \u003c/td\u003e\n                    \u003c/tr\u003e\n                \u003c/table\u003e\n                \u003c/td\u003e\n            \u003c/tr\u003e\n            \u003c/table\u003e\")\n    .Block(m =\u003e m.Content)\n    .Body(m =\u003e @\"\u003chtml\u003e... (see the examples for the complete source) ...\u003c/html\u003e\");\n\nvar body = MailBody\n    .CreateBody(template)\n    .Paragraph(\"Please confirm your email address by clicking the link below.\")\n    .Paragraph(\"We may need to send you critical information about our service and it is important that we have an accurate email address.\")\n    .Button(\"https://example.com/\", \"Confirm Email Address\")\n    .Paragraph(\"— [Insert company name here]\")\n    .ToString();\n```\n\n[Preview](https://doxakis.github.io/MailBody/src/Example/Output/OverrideDefaultTemplate.html)\n\n# Copyright and license\nCode released under the MIT license.\n","funding_links":[],"categories":["Frameworks, Libraries and Tools","框架, 库和工具","Mail"],"sub_categories":["Mail","邮件"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdoxakis%2FMailBody","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdoxakis%2FMailBody","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdoxakis%2FMailBody/lists"}