{"id":37023580,"url":"https://github.com/bvfalcon/junit5-fakesmtp","last_synced_at":"2026-01-14T02:50:18.477Z","repository":{"id":51684744,"uuid":"520433184","full_name":"bvfalcon/junit5-fakesmtp","owner":"bvfalcon","description":"FakeSMTP for unit-testing smtp clients with JUnit 5","archived":false,"fork":false,"pushed_at":"2023-01-11T17:30:53.000Z","size":48,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-04T08:11:40.222Z","etag":null,"topics":["junit","junit5","maven","smtp","smtp-server","testing","unit-testing"],"latest_commit_sha":null,"homepage":"https://bvfalcon.github.io/junit5-fakesmtp/","language":"Java","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/bvfalcon.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-08-02T09:29:26.000Z","updated_at":"2023-04-12T11:08:03.000Z","dependencies_parsed_at":"2023-02-09T04:01:20.098Z","dependency_job_id":null,"html_url":"https://github.com/bvfalcon/junit5-fakesmtp","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/bvfalcon/junit5-fakesmtp","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bvfalcon%2Fjunit5-fakesmtp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bvfalcon%2Fjunit5-fakesmtp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bvfalcon%2Fjunit5-fakesmtp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bvfalcon%2Fjunit5-fakesmtp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bvfalcon","download_url":"https://codeload.github.com/bvfalcon/junit5-fakesmtp/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bvfalcon%2Fjunit5-fakesmtp/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28408773,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T01:52:23.358Z","status":"online","status_checked_at":"2026-01-14T02:00:06.678Z","response_time":107,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","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":["junit","junit5","maven","smtp","smtp-server","testing","unit-testing"],"created_at":"2026-01-14T02:50:17.566Z","updated_at":"2026-01-14T02:50:18.470Z","avatar_url":"https://github.com/bvfalcon.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JUnit5-FakeSMTP\n[![Maven Central](https://maven-badges.herokuapp.com/maven-central/name.bychkov/junit5-fakesmtp/badge.svg?style=flat-square)](https://maven-badges.herokuapp.com/maven-central/name.bychkov/junit5-fakesmtp)\n\nFakeSMTP for unit-testing smtp clients with JUnit 5\n\n# Unit-testing with fake smtp-server\n\n## Problem description\n\nSuppose, your application sends emails to users with such or similar code:\n\n```java\npublic class SendEmailService {\n\n\tpublic void sendMessage(String email, String subject, String body) throws MessagingException {\n\t\tProperties props = System.getProperties();\n\t\tprops.put(\"mail.smtp.host\", \"localhost\");\n\t\tprops.put(\"mail.smtp.port\", \"25\");\n\t\tSession session = Session.getInstance(props, null);\n\t\t\n\t\tMessage simpleMail = new MimeMessage(session);\n\t\n\t\tsimpleMail.setSubject(subject);\n\t\tsimpleMail.setRecipient(Message.RecipientType.TO, new InternetAddress(email));\n\t\n\t\tMimeMultipart mailContent = new MimeMultipart();\n\t\n\t\tMimeBodyPart mailMessage = new MimeBodyPart();\n\t\tmailMessage.setContent(body, \"text/html; charset=utf-8\");\n\t\tmailContent.addBodyPart(mailMessage);\n\t\n\t\tsimpleMail.setContent(mailContent);\n\t\n\t\tTransport.send(simpleMail);\n\t}\n}\n```\n\nYou must be sure this functionality will work correct in future and not break, while the code changes. How can you do this? Every time you can start simple smpt-server locally. After tests runned, see messages and prove it. For small projects this is only uncomfortable, for large - impossible.\n\n## Solution\n\nThese actions can be performed automatically. Use in code of your unit-test special extension and smtp-server will start and stop automatically:\n\n```java\n\t@RegisterExtension\n\tstatic FakeSmtpJUnitExtension fakeSmtp = new FakeSmtpJUnitExtension();\n\t\n\t@Test\n\tpublic void testSendMessage() {\n\t\tString expectedReceiver = \"test-email-\" + new Random().nextInt(Integer.MAX_VALUE) + \"@example.com\";\n\t\tString expectedSubject = \"test-subject-\" + new Random().nextInt(Integer.MAX_VALUE);\n\t\t\n\t\ttry {\n\t\t\tSendEmailService testedService = new SendEmailService();\n\t\t\ttestedService.sendMessage(expectedReceiver, expectedSubject, \"text of body\");\n\t\t\t\n\t\t\tAssertions.assertEquals(1, fakeSmtp.getMessages().size());\n\t\t\tMimeMessage actualMail = fakeSmtp.getMessages().iterator().next();\n\t\t\tAssertions.assertEquals(expectedReceiver, actualMail.getAllRecipients()[0].toString());\n\t\t\tAssertions.assertEquals(expectedSubject, actualMail.getSubject());\n\t\t} catch (MessagingException e) {\n\t\t\tAssertions.fail(e);\n\t\t}\n\t}\n```\n\n# Minimum requirements\n- Java 8\n- Maven 3.2.5\n- JUnit 5.1\n\n# Using in your project\n\nAdd in your pom.xml these modifications\n\n```xml\n\u003cdependencies\u003e\n\t...\n\t\u003c!-- other dependencies --\u003e\n\t\u003c!-- JUnit 5 dependencies --\u003e\n\t...\n\t\u003cdependency\u003e\n\t\t\u003cgroupId\u003ename.bychkov\u003c/groupId\u003e\n\t\t\u003cartifactId\u003ejunit5-fakesmtp\u003c/artifactId\u003e\n\t\t\u003cversion\u003e1.0-SNAPSHOT\u003c/version\u003e\n\t\t\u003cscope\u003etest\u003c/scope\u003e\n\t\u003c/dependency\u003e\n\u003c/dependencies\u003e\n\n\u003cbuild\u003e\n\t\u003cplugins\u003e\n\t\t...\n\t\t\u003cplugin\u003e\n\t\t\t\u003cartifactId\u003emaven-surefire-plugin\u003c/artifactId\u003e\n\t\t\t\u003cversion\u003e2.22.0\u003c/version\u003e\n\t\t\u003c/plugin\u003e\n\t\u003c/plugins\u003e\n\u003c/build\u003e\n```\n\nNotes:\n\n1) maven-surefire-plugin must have version \u003e= 2.22.0\n\n## JavaMail and Jakarta Mail\n\nBy default, implementation uses JavaMail realization (namespaces `javax.mail.`). If you use Jakarta Mail (namespaces `jakarta.mail.`), use dependency with classifier `jakarta`:\n\n```xml\n\u003cdependency\u003e\n\t\u003cgroupId\u003ename.bychkov\u003c/groupId\u003e\n\t\u003cartifactId\u003ejunit5-fakesmtp\u003c/artifactId\u003e\n\t\u003cversion\u003e1.0-SNAPSHOT\u003c/version\u003e\n\t\u003cclassifier\u003ejakarta\u003c/classifier\u003e\n\t\u003cscope\u003etest\u003c/scope\u003e\n\u003c/dependency\u003e\n```\n\n## More samples\n\nYou can see full examples of usage JUnit5-FakeSMTP with [JavaMail](./src/it/javamail/) and [Jakarta Mail](./src/it/jakartamail/).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbvfalcon%2Fjunit5-fakesmtp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbvfalcon%2Fjunit5-fakesmtp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbvfalcon%2Fjunit5-fakesmtp/lists"}