{"id":18484088,"url":"https://github.com/iankoex/cloudflaredomainsemailkit","last_synced_at":"2025-04-08T18:33:05.802Z","repository":{"id":198097757,"uuid":"700052913","full_name":"iankoex/CloudflareDomainsEmailKit","owner":"iankoex","description":"Send Emails From Your Cloudflare Domains Email using Swift","archived":false,"fork":false,"pushed_at":"2024-08-25T05:35:55.000Z","size":29,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-08T06:20:07.459Z","etag":null,"topics":["cloudflare","emails","mailchannels","swift","vapor"],"latest_commit_sha":null,"homepage":"","language":"Swift","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/iankoex.png","metadata":{"files":{"readme":"README.md","changelog":null,"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,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-10-03T21:11:05.000Z","updated_at":"2024-08-25T05:35:58.000Z","dependencies_parsed_at":"2024-05-15T18:23:56.888Z","dependency_job_id":"96a651e5-266d-44ed-80af-a311df32bc86","html_url":"https://github.com/iankoex/CloudflareDomainsEmailKit","commit_stats":null,"previous_names":["iankoex/cloudflaredomainsemailkit"],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iankoex%2FCloudflareDomainsEmailKit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iankoex%2FCloudflareDomainsEmailKit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iankoex%2FCloudflareDomainsEmailKit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iankoex%2FCloudflareDomainsEmailKit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/iankoex","download_url":"https://codeload.github.com/iankoex/CloudflareDomainsEmailKit/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247902716,"owners_count":21015502,"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":["cloudflare","emails","mailchannels","swift","vapor"],"created_at":"2024-11-06T12:38:35.408Z","updated_at":"2025-04-08T18:33:00.785Z","avatar_url":"https://github.com/iankoex.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CloudflareDomainsEmailKit ⚠️\n\nSend Emails From Your Cloudflare Domains Email using Swift\n\n## ⚠️ MailChannels End of Life Notice - Cloudflare Workers\n\u003e Since launching our free email sending API for Cloudflare Workers customers, we have been proud to provide a simple yet effective solution to deliver messages from Workers code with a minimum of setup complexity. Unfortunately, we regret to announce that this free service will be coming to an end on June 30th, 2024.\n\nRead the full announcement [here](https://support.mailchannels.com/hc/en-us/articles/26814255454093-End-of-Life-Notice-Cloudflare-Workers)\n\nSince sending emails via mailchannels from a cloudflare worker is no longer possible, this package will not work.\n\n# Requirements\n\n1. A Cloudflare domain\n\n# Usage\n\nMailChannels Send API lets you send emails from your Cloudflare Workers apps. Learn more about MailChannels [here.](https://support.mailchannels.com/hc/en-us/articles/4565898358413-Sending-Email-from-Cloudflare-Workers-using-MailChannels-Send-API)\n\nYou do not need an account with MailChannels to start sending emails\n\nHowever, you are required to have a Domain Lockdown DNS record authorizing your Worker to send emails for your domain.\n\nFor our use case do the following:\n\n## 1. Set up Sender Policy Framework(SPF) Records\n\nThe following records are needed for SPF to work correctly.\n\n| Location                   | Record Type | Value                                           |\n| -------------------------- | ----------- | ----------------------------------------------- |\n| example.com                | TXT         | v=spf1 a mx include:relay.mailchannels.net ~all |\n| \\_mailchannels.example.com | TXT         | v=mc1 cfid=myapp.workers.dev                    |\n\nReplace `example.com` with your domain name.\n\nYou are likely to have configured email routing for your domain and therefore, you have an existing TXT record pointing to the root of your domain.\n\nIn this case update your record to something that looks like `v=spf1 include:_spf.mx.cloudflare.net include:relay.mailchannels.net ~all`\n\nReplace `cfid=myapp.workers.dev` with the `cfid` of the worker that will be resposible for emails (more on this in section 2),\n\nYour cfid is located at [dash.cloudflare.com](dash.cloudflare.com) \u003e Workers \u0026 Pages \u003e Overview. Beneath \"Your subdomain\" at the right side of the page.\n\n## 2. Create your Worker\n\nOn the Workers \u0026 Pages Overview Page, click on Create Application.\n\nCreate and deploy a Hello World script. You can only edit the worker after deployment.\n\nReplace the code with the following, then click on save and deploy.\n\n```javascript\nasync function readRequestBody(request) {\n  const { headers } = request;\n  const contentType = headers.get(\"content-type\") || \"\";\n  if (contentType.includes(\"application/json\")) {\n    return JSON.stringify(await request.json());\n  } else {\n    return '{\"success\":false}';\n  }\n}\n\nasync function handleRequest(request) {\n  let start = Date.now();\n  let reqBody = await readRequestBody(request);\n  let sendRequest = new Request(\"https://api.mailchannels.net/tx/v1/send\", {\n    method: \"POST\",\n    headers: {\n      \"content-type\": \"application/json\",\n    },\n    body: reqBody,\n  });\n  let resp = await fetch(sendRequest);\n  let respText = await resp.text();\n  let end = Date.now();\n  let total = end - start;\n  return new Response(respText, {\n    headers: {\n      \"X-MC-Status\": `${resp.status}`,\n      \"X-MC-Status-Text\": resp.statusText,\n      \"X-Response-Time\": `${total}`,\n    },\n  });\n}\n\naddEventListener(\"fetch\", (event) =\u003e {\n  const { request } = event;\n\n  if (request.method === \"POST\") {\n    return event.respondWith(handleRequest(request));\n  } else if (request.method === \"GET\") {\n    return event.respondWith(new Response(`The request was a GET`));\n  }\n});\n```\n\nTake note of the domain of your worker you will need that for section 3\n\n## 3. Sending emails from Swift Server\n\nTo get started, add the CloudflareDomainsEmailKit dependency:\n\n```swift\n.package(url: \"https://github.com/iankoex/CloudflareDomainsEmailKit.git\", from: \"0.1.4\")\n```\n\nAnd add it as a dependency of your target:\n\n```swift\n.product(name: \"CloudflareDomainsEmailKit\", package: \"CloudflareDomainsEmailKit\")\n```\n\nCreate the content.\n\n```swift\nlet content = EmailContent(\n    personalizations: [\n        EmailContent.Personalization(\n            recipients: [\n                MailUser(name: \"User 1\", email: \"username@email.com\")\n            ]\n        )\n    ],\n    from: MailUser(name: \"Support\", email: \"support@example.com\"),\n    subject: \"Your App Data\",\n    content: [\n        EmailContent.EmailBody(type: .plainText,value: \"This is the email's body\")\n    ]\n)\n```\n\nSend the email.\n\n``` swift \ntry await EmailClient.sendMail(content: content, using: \"https://app.workers.dev/\")\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiankoex%2Fcloudflaredomainsemailkit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fiankoex%2Fcloudflaredomainsemailkit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiankoex%2Fcloudflaredomainsemailkit/lists"}