{"id":94,"date":"2009-09-25T10:11:13","date_gmt":"2009-09-25T08:11:13","guid":{"rendered":"http:\/\/www.limilabs.com\/blog\/?p=94"},"modified":"2009-09-25T10:11:13","modified_gmt":"2009-09-25T08:11:13","slug":"how-to-test-email-sending","status":"publish","type":"post","link":"https:\/\/www.limilabs.com\/blog\/how-to-test-email-sending","title":{"rendered":"How to test email sending?"},"content":{"rendered":"<p>Nearly every web application these days sends some notifications to its users.<\/p>\n<p>Many times before, I came across people who said that it&#8217;s not possible to test such things.<br \/>\nWell, they are wrong!<\/p>\n<p>There is a very cool project on sourceforge called <strong>nDumbster<\/strong>:<br \/>\n<a href=\"http:\/\/ndumbster.sourceforge.net\">http:\/\/ndumbster.sourceforge.net<\/a><\/p>\n<p>nDumbster is a simple fake SMTP server designed especially to enable unit testing.<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\n&#x5B;TestFixture]\npublic class SmtpClientTest\n{\n    private const int _port = 25;\n    private SimpleSmtpServer _smtpServer;\n\n    &#x5B;SetUp]\n    public void SetUp()\n    {\n        _smtpServer = SimpleSmtpServer.Start(_port);\n    }\n\n    &#x5B;TearDown]\n    public void TearDown()\n    {\n        _smtpServer.Stop();\n    }\n\n    &#x5B;Test]\n    public void SendMessage_SendsMessage()\n    {\n        Mail.Text(&quot;Some tex&quot;)\n            .Subject(&quot;Some subject&quot;)\n            .From(new MailBox(&quot;alice@mail.com&quot;, &quot;Alice&quot;))\n            .To(new MailBox(&quot;bob@mail.com&quot;, &quot;Bob&quot;))\n            .UsingNewSmtp()\n            .Server(&quot;localhost&quot;)\n            .OnPort(_port)\n            .Send();\n\n        Assert.AreEqual(1, _smtpServer.ReceivedEmailCount);\n        SmtpMessage mail = _smtpServer.ReceivedEmail&#x5B;0];\n        Assert.AreEqual(&quot;&quot;Alice&quot; &lt;alice@mail.com&gt;&quot;, mail.Headers&#x5B;&quot;From&quot;]);\n        Assert.AreEqual(&quot;&quot;Bob&quot; &lt;bob@mail.com&gt;&quot;, mail.Headers&#x5B;&quot;To&quot;]);\n        Assert.AreEqual(&quot;Some subject&quot;, mail.Headers&#x5B;&quot;Subject&quot;]);\n        Assert.AreEqual(&quot;Some text&quot;, mail.Body);\n    }\n};\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Nearly every web application these days sends some notifications to its users. Many times before, I came across people who said that it&#8217;s not possible to test such things. Well, they are wrong! There is a very cool project on sourceforge called nDumbster: http:\/\/ndumbster.sourceforge.net nDumbster is a simple fake SMTP server designed especially to enable [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,8],"tags":[15,56],"class_list":["post-94","post","type-post","status-publish","format-standard","hentry","category-programming","category-tools","tag-c","tag-unit-testing"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/94"}],"collection":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/comments?post=94"}],"version-history":[{"count":0,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/94\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/media?parent=94"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/categories?post=94"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/tags?post=94"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}