{"id":19324588,"url":"https://github.com/stanislas-m/mocksmtp","last_synced_at":"2025-04-22T19:32:53.663Z","repository":{"id":57480463,"uuid":"138384189","full_name":"stanislas-m/mocksmtp","owner":"stanislas-m","description":"A Mock SMTP for Buffalo","archived":false,"fork":false,"pushed_at":"2019-07-05T06:27:44.000Z","size":38,"stargazers_count":9,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-05-02T05:08:25.750Z","etag":null,"topics":["go","gobuffalo","golang","mock","smtp","testing"],"latest_commit_sha":null,"homepage":null,"language":"Go","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/stanislas-m.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":"2018-06-23T08:20:24.000Z","updated_at":"2024-05-02T05:08:25.751Z","dependencies_parsed_at":"2022-09-26T17:41:14.583Z","dependency_job_id":null,"html_url":"https://github.com/stanislas-m/mocksmtp","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stanislas-m%2Fmocksmtp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stanislas-m%2Fmocksmtp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stanislas-m%2Fmocksmtp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stanislas-m%2Fmocksmtp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stanislas-m","download_url":"https://codeload.github.com/stanislas-m/mocksmtp/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223903550,"owners_count":17222551,"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":["go","gobuffalo","golang","mock","smtp","testing"],"created_at":"2024-11-10T02:06:01.919Z","updated_at":"2024-11-10T02:06:02.549Z","avatar_url":"https://github.com/stanislas-m.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"MockSMTP\n========\n\nMockSMTP is an in-memory implementation for buffalo `Sender` interface. It's intended to catch sent messages for test purposes.\n\nUsage\n-----\n\nmailers/mailers_test.go:\n```go\npackage mailers_test\n\nimport (\n\t\"github.com/stanislas-m/mocksmtp\"\n\t\"gitlab.com/stanislas-m/mybuffaloproject/mailers\"\n)\n\nfunc init() {\n\tmailers.SMTP = mocksmtp.New()\n}\n\n```\n\nmailers/registration_mail.go:\n```go\npackage mailers\n\nimport (\n\t\"github.com/gobuffalo/buffalo/mail\"\n\t\"github.com/gobuffalo/buffalo/render\"\n\t\"github.com/pkg/errors\"\n)\n\nfunc SendRegistrationMail(email string) error {\n\tm := mail.NewMessage()\n\n\tm.Subject = \"Registration succeed\"\n\tm.From = \"Buffalo \u003cnoreply@gobuffalo.io\u003e\"\n\tm.To = []string{email}\n\terr := m.AddBody(r.HTML(\"registration_mail.html\"), render.Data{})\n\tif err != nil {\n\t\treturn errors.WithStack(err)\n\t}\n\tif err := SMTP.Send(m); err != nil {\n\t\treturn errors.WithStack(err)\n\t}\n\treturn nil\n}\n\n```\n\nmailers/registration_mail_test.go:\n```go\npackage mailers_test\n\nimport (\n\t\"testing\"\n\n\t\"github.com/stretchr/testify/require\"\n\t\"gitlab.com/stanislas-m/mybuffaloproject/mailers\"\n)\n\nfunc Test_SendRegistrationMail(t *testing.T) {\n    r := require.New(t)\n    ms, v := mailers.SMTP.(*mocksmtp.MockSMTP)\n    r.True(v)\n    // Clear SMTP queue after test\n    defer ms.Clear()\n    err := mailers.SendRegistrationMail(\"test@gobuffalo.io\")\n    r.NoError(err)\n    // Test email\n    r.Equal(1, ms.Count())\n    m, err := ms.LastMessage()\n    r.NoError(err)\n    r.Equal(\"Buffalo \u003cnoreply@gobuffalo.io\u003e\", m.From)\n    r.Equal(\"Registration succeed\", m.Subject)\n    r.Equal(1, len(m.To))\n    r.Equal(\"test@gobuffalo.io\", m.To[0])\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstanislas-m%2Fmocksmtp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstanislas-m%2Fmocksmtp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstanislas-m%2Fmocksmtp/lists"}