{"id":20037969,"url":"https://github.com/perfectlysoft/perfect-smtp","last_synced_at":"2025-05-05T06:31:47.795Z","repository":{"id":63920182,"uuid":"77763687","full_name":"PerfectlySoft/Perfect-SMTP","owner":"PerfectlySoft","description":"SMTP Client for Perfect.","archived":false,"fork":false,"pushed_at":"2020-07-14T22:07:52.000Z","size":70,"stargazers_count":22,"open_issues_count":3,"forks_count":18,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-19T18:35:55.238Z","etag":null,"topics":["perfect","server-side-swift","smtp","smtp-library","smtpclient","swift"],"latest_commit_sha":null,"homepage":"https://www.perfect.org","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/PerfectlySoft.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}},"created_at":"2017-01-01T02:52:12.000Z","updated_at":"2024-06-14T04:21:28.000Z","dependencies_parsed_at":"2023-01-14T14:00:33.909Z","dependency_job_id":null,"html_url":"https://github.com/PerfectlySoft/Perfect-SMTP","commit_stats":null,"previous_names":[],"tags_count":35,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PerfectlySoft%2FPerfect-SMTP","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PerfectlySoft%2FPerfect-SMTP/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PerfectlySoft%2FPerfect-SMTP/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PerfectlySoft%2FPerfect-SMTP/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PerfectlySoft","download_url":"https://codeload.github.com/PerfectlySoft/Perfect-SMTP/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252451578,"owners_count":21749954,"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":["perfect","server-side-swift","smtp","smtp-library","smtpclient","swift"],"created_at":"2024-11-13T10:24:12.782Z","updated_at":"2025-05-05T06:31:47.464Z","avatar_url":"https://github.com/PerfectlySoft.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Perfect - SMTP [简体中文](README.zh_CN.md)\n\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"http://perfect.org/get-involved.html\" target=\"_blank\"\u003e\n        \u003cimg src=\"http://perfect.org/assets/github/perfect_github_2_0_0.jpg\" alt=\"Get Involed with Perfect!\" width=\"854\" /\u003e\n    \u003c/a\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://github.com/PerfectlySoft/Perfect\" target=\"_blank\"\u003e\n        \u003cimg src=\"http://www.perfect.org/github/Perfect_GH_button_1_Star.jpg\" alt=\"Star Perfect On Github\" /\u003e\n    \u003c/a\u003e  \n    \u003ca href=\"http://stackoverflow.com/questions/tagged/perfect\" target=\"_blank\"\u003e\n        \u003cimg src=\"http://www.perfect.org/github/perfect_gh_button_2_SO.jpg\" alt=\"Stack Overflow\" /\u003e\n    \u003c/a\u003e  \n    \u003ca href=\"https://twitter.com/perfectlysoft\" target=\"_blank\"\u003e\n        \u003cimg src=\"http://www.perfect.org/github/Perfect_GH_button_3_twit.jpg\" alt=\"Follow Perfect on Twitter\" /\u003e\n    \u003c/a\u003e  \n    \u003ca href=\"http://perfect.ly\" target=\"_blank\"\u003e\n        \u003cimg src=\"http://www.perfect.org/github/Perfect_GH_button_4_slack.jpg\" alt=\"Join the Perfect Slack\" /\u003e\n    \u003c/a\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://developer.apple.com/swift/\" target=\"_blank\"\u003e\n        \u003cimg src=\"https://img.shields.io/badge/Swift-4.1-orange.svg?style=flat\" alt=\"Swift 4.1\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://developer.apple.com/swift/\" target=\"_blank\"\u003e\n        \u003cimg src=\"https://img.shields.io/badge/Platforms-OS%20X%20%7C%20Linux%20-lightgray.svg?style=flat\" alt=\"Platforms OS X | Linux\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"http://perfect.org/licensing.html\" target=\"_blank\"\u003e\n        \u003cimg src=\"https://img.shields.io/badge/License-Apache-lightgrey.svg?style=flat\" alt=\"License Apache\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"http://twitter.com/PerfectlySoft\" target=\"_blank\"\u003e\n        \u003cimg src=\"https://img.shields.io/badge/Twitter-@PerfectlySoft-blue.svg?style=flat\" alt=\"PerfectlySoft Twitter\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"http://perfect.ly\" target=\"_blank\"\u003e\n        \u003cimg src=\"http://perfect.ly/badge.svg\" alt=\"Slack Status\"\u003e\n    \u003c/a\u003e\n\u003c/p\u003e\n\n\n\nThis project provides an SMTP library.\n\nThis package builds with Swift Package Manager and is part of the [Perfect](https://github.com/PerfectlySoft/Perfect) project.\n\nEnsure you have installed and activated the latest Swift 4.1.1 tool chain.\n\n## Linux Build Note\n\nPlease make sure libssl-dev was installed on Ubuntu 16.04:\n\n```\n$ sudo apt-get install libssl-dev\n```\n\n## The Best Practice\n\nPrior to code with Perfect-SMTP, please feel free to try [SMTP command line example by curl](https://ec.haxx.se/usingcurl-smtp.html).\n\nThis command line tool can be helpful to understand the SMTP protocol and the objective server you are going to work with.\n\n\n## Quick Start\n\nTo use SMTP class, please modify the Package.swift file and add following dependency:\n\n``` swift\n.package(url: \"https://github.com/PerfectlySoft/Perfect-SMTP.git\", from: \"3.0.0\")\n```\n\nThen please import SMTP library into the swift source code:\n\n``` swift\nimport PerfectSMTP\n```\n\n## Data Structures\n\nPerfect SMTP contains three different data structures: SMTPClient, Recipient and EMail.\n\n### SMTPClient\n\nSMTPClient object is a data structure to store mail server login information:\n\n``` swift\nlet client = SMTPClient(url: \"smtp://mailserver.address\", username: \"someone@some.where\", password:\"secret\")\n```\n\n### Recipient\n\nRecipient object is a data structure which store one's name and email address:\n\n``` swift\nlet recipient = Recipient(name: \"Someone's Full Name\", address: \"someone@some.where\")\n```\n\n### EMail\n\nUsing email object to compose and send an email. Check the following example code:\n\n``` swift\n// initialize an email draft with mail connection / login info\nvar email = EMail(client: client)\n\n// set the title of email\nemail.subject = \"Mail Title\"\n\n// set the sender info\nemail.from = Recipient(name: \"My Full Name\", address: \"mynickname@my.home\")\n\n// fill in the main content of email, plain text or html\nemail.html = \"\u003ch1\u003eHello, world!\u003c/h1\u003e\u003chr\u003e\u003cimg src='http://www.perfect.org/images/perfect-logo-2-0.svg'\u003e\"\n\n// set the mail recipients, to / cc / bcc are all arrays\nemail.to.append(Recipient(name: \"First Receiver\", address: \"someone@some.where\"))\nemail.cc.append(Recipient(name: \"Second Receiver\", address: \"someOtherOne@some.where\"))\nemail.bcc.append(Recipient(name: \"An invisible receiver\", address: \"someoneElse@some.where\"))\n\n// add attachments\nemail.attachments.append(\"/path/to/file.txt\")\nemail.attachments.append(\"/path/to/img.jpg\")\n\n// send the email and call back if done.\ndo {\n  try email.send { code, header, body in\n    /// response info from mail server\n    print(code)\n    print(header)\n    print(body)\n  }//end send\n}catch(let err) {\n  /// something wrong\n}\n```\n\n#### Members of EMail Object\n\n- client: SMTPClient, login info for mail server connection\n- to: [Recipient], array of mail recipients\n- cc: [Recipient], array of mail recipients, \"copy / forward\"\n- bcc:[Recipient], array of mail recipients, will not appear in the to / cc mail.\n- from: Recipient, email address of the current sender\n- subject: String, title of the email\n- attachments: [String], full path of attachments, i.e., [\"/path/to/file1.txt\", \"/path/to/file2.gif\" ...]\n- content: String, mail body in text, plain text or html\n- html: String, alias of `content` (share the same variable as `content`)\n- text: String, set the content to plain text\n- send(completion: @escaping ((Int, String, String)-\u003eVoid)), function of sending email with callback.\nThe completion callback has three parameters, please check Perfect-CURL `performFully()` for more information:\n  - code: Int, mail server response code. Zero for OK.\n  - header: String, mail server response header string.\n  - body: String, mail server response body string.\n\n\n## Example\n\nA demo can be found here:\n[Perfect SMTP Demo](https://github.com/PerfectExamples/Perfect-SMTP-Demo)\n\n## Tips for SMTPS\n\nWe've received a lot of requests about google smtp examples, Thanks for @ucotta @james and of course the official Perfect support from @iamjono, this note might be helpful for building gmail applications: ⚠️*the SMTPClient url needs to be `smtps://smtp.gmail.com`, and you may need to [“turn on access for less secure apps”](https://myaccount.google.com/lesssecureapps) in the google settings.*⚠️\n\nPlease check the SMTPS code below, note the only difference is the URL pattern:\n\n``` swift\nimport PerfectSMTP\n\nlet client = SMTPClient(url: \"smtps://smtp.gmail.com\", username: \"yourname@gmail.com\", password:\"yourpassword\")\n\nvar email = EMail(client: client)\n\nemail.subject = \"a topic\"\nemail.content = \"a message\"\n\nemail.cc.append(Recipient(address: \"who@where.com\"))\n\ndo {\n  try email.send { code, header, body in\n    /// response info from mail server\n    print(code)\n  }//end send\n}catch(let err) {\n  /// something wrong\n}\n```\n\n\n## Further Information\nFor more information on the Perfect project, please visit [perfect.org](http://perfect.org).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fperfectlysoft%2Fperfect-smtp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fperfectlysoft%2Fperfect-smtp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fperfectlysoft%2Fperfect-smtp/lists"}