<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>AboutCode.net - asp</title>
    <link>http://www.aboutcode.net/</link>
    <description>Thoughts on Software by Andrew Davey</description>
    <language>en-us</language>
    <copyright>Andrew Davey</copyright>
    <lastBuildDate>Mon, 19 Jan 2009 16:39:44 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.2.8279.16125</generator>
    <managingEditor>andrew@equin.co.uk</managingEditor>
    <webMaster>andrew@equin.co.uk</webMaster>
    <item>
      <trackback:ping>http://www.aboutcode.net/Trackback.aspx?guid=c9d9ee2e-555e-4b7f-8509-8bd8a9dcc5ad</trackback:ping>
      <pingback:server>http://www.aboutcode.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.aboutcode.net/PermaLink,guid,c9d9ee2e-555e-4b7f-8509-8bd8a9dcc5ad.aspx</pingback:target>
      <dc:creator>Andrew Davey</dc:creator>
      <wfw:comment>http://www.aboutcode.net/CommentView,guid,c9d9ee2e-555e-4b7f-8509-8bd8a9dcc5ad.aspx</wfw:comment>
      <wfw:commentRss>http://www.aboutcode.net/SyndicationService.asmx/GetEntryCommentsRss?guid=c9d9ee2e-555e-4b7f-8509-8bd8a9dcc5ad</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Don't call SmtpClient.SendMail directly within your controller actions because it
directly couples your controller to SmtpClient.
</p>
        <p>
Don't even create an interface IMailer and wrapping implementation of this to SmtpClient.
</p>
        <p>
Instead, create a new ActionResult subclass called EmailResult. Make this class have
the properties From, To, Subject and BodyData. In the ExecuteResult method use the
ViewEngine infrastructure to render a view of the BodyData into your own StringWriter.
You can then send the resulting content via email using SmtpClient.
</p>
        <img width="0" height="0" src="http://www.aboutcode.net/aggbug.ashx?id=c9d9ee2e-555e-4b7f-8509-8bd8a9dcc5ad" />
      </body>
      <title>Email ActionResult in ASP.NET MVC</title>
      <guid isPermaLink="false">http://www.aboutcode.net/PermaLink,guid,c9d9ee2e-555e-4b7f-8509-8bd8a9dcc5ad.aspx</guid>
      <link>http://www.aboutcode.net/2009/01/19/EmailActionResultInASPNETMVC.aspx</link>
      <pubDate>Mon, 19 Jan 2009 16:39:44 GMT</pubDate>
      <description>&lt;p&gt;
Don't call SmtpClient.SendMail directly within your controller actions because it
directly couples your controller to SmtpClient.
&lt;/p&gt;
&lt;p&gt;
Don't even create an interface IMailer and wrapping implementation of this to SmtpClient.
&lt;/p&gt;
&lt;p&gt;
Instead, create a new ActionResult subclass called EmailResult. Make this class have
the properties From, To, Subject and BodyData. In the ExecuteResult method use the
ViewEngine infrastructure to render a view of the BodyData into your own StringWriter.
You can then send the resulting content via email using SmtpClient.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.aboutcode.net/aggbug.ashx?id=c9d9ee2e-555e-4b7f-8509-8bd8a9dcc5ad" /&gt;</description>
      <comments>http://www.aboutcode.net/CommentView,guid,c9d9ee2e-555e-4b7f-8509-8bd8a9dcc5ad.aspx</comments>
      <category>.net</category>
      <category>asp</category>
      <category>mvc</category>
      <category>web</category>
    </item>
  </channel>
</rss>