{"id":29651443,"url":"https://github.com/eval/uri-smtp","last_synced_at":"2025-10-15T15:32:17.018Z","repository":{"id":305102624,"uuid":"1021335257","full_name":"eval/uri-smtp","owner":"eval","description":"Parse and handle SMTP URIs","archived":false,"fork":false,"pushed_at":"2025-07-18T10:31:05.000Z","size":8,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-07-18T11:13:29.857Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Ruby","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/eval.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","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,"zenodo":null}},"created_at":"2025-07-17T08:42:23.000Z","updated_at":"2025-07-18T10:31:08.000Z","dependencies_parsed_at":"2025-07-18T11:25:51.100Z","dependency_job_id":null,"html_url":"https://github.com/eval/uri-smtp","commit_stats":null,"previous_names":["eval/uri-smtp"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/eval/uri-smtp","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eval%2Furi-smtp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eval%2Furi-smtp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eval%2Furi-smtp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eval%2Furi-smtp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eval","download_url":"https://codeload.github.com/eval/uri-smtp/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eval%2Furi-smtp/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266434166,"owners_count":23927914,"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-07-22T02:00:09.085Z","response_time":66,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"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":"2025-07-22T05:35:32.563Z","updated_at":"2025-10-15T15:32:17.012Z","avatar_url":"https://github.com/eval.png","language":"Ruby","readme":"# URI::SMTP [![Gem Version](https://badge.fury.io/rb/uri-smtp.svg)](https://badge.fury.io/rb/uri-smtp) [![API Docs](https://img.shields.io/badge/API%20Docs-YARD-red?style=flat-square\u0026logo=ruby)](https://eval.github.io/uri-smtp/)\n\nExtends Ruby's `URI` with support for SMTP-uri's.  \nThis allows for more concise SMTP-config:\n```diff\n# config/environments/production.rb\nconfig.action_mailer.delivery_method = :smtp\n- config.action_mailer.smtp_settings = {\n-   address:         \"smtp.gmail.com\",\n-   port:            587,\n-   domain:          \"example.com\",\n-   user_name:       Rails.application.credentials.dig(:smtp, :user_name),\n-   password:        Rails.application.credentials.dig(:smtp, :password),\n-   authentication:  \"plain\",\n-   enable_starttls: true,\n-   open_timeout:    5,\n-   read_timeout:    5\n- }\n# given ENV[\"SMPT_URL\"]:\n# \"smtp://user_name:password@smtp.gmail.com?open_timeout=5\u0026read_timeout=5#example.com\"\n+ config.action_mailer.smtp_settings = URI(ENV.fetch(\"SMTP_URL\")).to_h(format: :am)\n```\n\n## Installation\n\nInstall the gem and add to the application's Gemfile by executing:\n\n```bash\nbundle add uri-smtp\n```\n\nIf bundler is not being used to manage dependencies, install the gem by executing:\n\n```bash\ngem install uri-smtp\n```\n\n## Usage\n\n### parse\n\n```ruby\nu = URI(\"smtps+login://user%40gmail.com:p%40ss@smtp.gmail.com#sender.org\")\n\nurl.scheme           #=\u003e \"smtps+login\"\nurl.auth             #=\u003e \"login\"\nurl.starttls         #=\u003e false\nurl.starttls?        #=\u003e false\nurl.tls?             #=\u003e true\nurl.userinfo         #=\u003e \"user%40gmail.com:p%40ss\"\nurl.decoded_userinfo #=\u003e \"user@gmail.com:p@ss\"\nurl.decoded_user     #=\u003e \"user@gmail.com\"\nurl.user             #=\u003e \"user%40gmail.com\"\nurl.decoded_password #=\u003e \"p@ss\"\nurl.password         #=\u003e \"p%40ss\"\nurl.host             #=\u003e \"smtp.gmail.com\"\nurl.port             #=\u003e 465\nurl.domain           #=\u003e \"sender.org\"\n```\n\n### to_h\n\n```ruby\nURI(\"smtps+login://user%40gmail.com:p%40ss@smtp.gmail.com?domain=sender.org\").to_h\n#=\u003e\n{auth: \"login\",\n domain: \"sender.org\",\n host: \"smtp.gmail.com\",\n port: 587,\n scheme: \"smtps+login\",\n starttls: :always,\n tls: false,\n user: \"user@gmail.com\",\n password: \"p@ss\"}\n```\n\nFor [ActionMailer configuration](https://guides.rubyonrails.org/action_mailer_basics.html#action-mailer-configuration), use `format: :action_mailer` (or `:am`):\n```ruby\nURI(\"smtps+login://user%40gmail.com:p%40ss@smtp.gmail.com?domain=sender.org\").to_h(format: :am)\n#=\u003e\n{address: \"smtp.gmail.com\",\n authentication: \"login\",\n domain: \"sender.org\",\n enable_starttls: :always,\n port: 587,\n user_name: \"user@gmail.com\",\n password: \"p@ss\"}\n```\n\nBesides renaming some keys, this also works around a quirk in `v2.8.1` of the mail-gem (e.g. `tls: false` [skips setting up STARTTLS](https://github.com/mikel/mail/blob/2.8.1/lib/mail/network/delivery_methods/smtp.rb#L115)).\n\n\nFull Rails config:\n```ruby\n    config.action_mailer.delivery_method = :smtp\n    # [mailcatcher](https://github.com/sj26/mailcatcher) fallback:\n    config.action_mailer.smtp_settings = URI(ENV.fetch(\"SMTP_URL\", \"smtp://127.0.0.1:1025\")).to_h(format: :am)\n```\n\n## SMTP-URI\n\nThere's no official specification for SMTP-URIs. There's some prior work though. This implementation is heavily inspired by [aerc](https://git.sr.ht/~rjarry/aerc/tree/master/item/doc/aerc-smtp.5.scd).  \n\n`\u003cscheme\u003e[+\u003cauth\u003e]://[\u003cuser\u003e[:\u003cpassword\u003e]@]\u003chost\u003e[:\u003cport\u003e][?\u003cquery\u003e][#\u003cfragment\u003e]`\n\n### scheme\n\n- `smtp`  \n  SMTP with STARTTLS (i.e. `url.starttls #=\u003e :always`).\n- `smtp+insecure`  \n  SMTP without STARTTLS (i.e. `url.starttls #=\u003e false`)..\n- `smtps`  \n  SMTP with TLS.\n\n\u003e [!NOTE]\n\u003e to get `url.starttls #=\u003e :auto`, provide it in the query: `smtp://user:pw@foo?auth=auto`. In that case `net-smtp` uses STARTTLS when the server supports it (but won't halt like when using `:always`).\n\n\n### auth\n\nAny value for auth that passes the URI-parser is acceptable. Though the following values have special meaning:\n\n- `none`  \n  No authentication is required.\n- `plain`  \n  Authenticate with a username and password using AUTH PLAIN. This is the default behavior when no authentication is provided.\n\n\u003e [!NOTE]\n\u003e any query's value for `auth` takes precedence.\n\n### Examples\n\n| SMTP URI | TLS? | Port | STARTTLS | Auth Method | Notes |\n|----------|---------|------|----------|-------------|-------|\n| `smtp://smtp.example.com` | ❌ | 587 | ⚡ | none | Standard submission with STARTTLS `:always` |\n| `smtp+insecure://smtp.example.com` | ❌ | 587 | ❌ | none | Standard submission without STARTTLS |\n| `smtp+insecure+login://user:pass@smtp.example.com` | ❌ | 587 | ❌ | login | Authenticate insecurely using LOGIN auth |\n| `smtp://smtp.example.com?starttls=auto` | ❌ | 587 | 🔄 | none | Standard submission with STARTTLS `:auto` |\n| `smtp://smtp.example.com:1025` | ❌ | 1025 | ⚡ | none | Standard submission with STARTTLS `:always` on custom port |\n| `smtp://user:pass@mail.example.com` | ❌ | 587 | ⚡ | plain | STARTTLS `:always` with (default) PLAIN auth |\n| `smtp+login://user:pass@mail.example.com` | ❌ | 587 | ⚡ | login | STARTTLS `:always` with LOGIN auth |\n| `smtp+none://mail.example.com` | ❌ | 587 | 🔄 | none | Explicit no authentication |\n| `smtps://mail.example.com` | ✅ | 465 | ❌ | none | Direct TLS connection |\n| `smtps://mail.example.com?domain=sender.org\u0026read_timeout=5\u0026open_timeout=5` | ✅ | 465 | ❌ | none | `domain`, `read_timeout` and `open_timeout` set |\n| `smtps+login://user@imap.gmail.com` | ✅ | 465 | ❌ | login | Direct TLS with LOGIN auth |\n| `smtps://user%40gmail.com:p%40ss@imap.gmail.com` | ✅ | 465 | ❌ | login | Direct TLS with encoded userinfo `user@gmail.com:p@ss` |\n| `smtp://localhost` | ❌ | 25 | ❌ | none | Local delivery (no encryption) |\n| `smtp://127.0.0.1` | ❌ | 25 | ❌ | none | Local delivery (no encryption) |\n\n**Legend**\n\n`STARTTLS`\n- ⚡ = `:always`  \n  Require STARTTLS (i.e. `net-smtp` aborts when server doesn't support STARTTLS).\n- 🔄 = `:auto`  \n  Use STARTTLS if supported by server.\n- ❌ = `false`  \n  No STARTTLS. This is always the case when using TLS.\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.\nUse `bin/yard server --reload` when working on documentation.\n\nTo install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/eval/uri-smtp.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feval%2Furi-smtp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feval%2Furi-smtp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feval%2Furi-smtp/lists"}