.NET and SMTP Configuration

Posted by koevoeter on ASP.net Weblogs See other posts from ASP.net Weblogs or by koevoeter
Published on Mon, 06 Dec 2010 12:53:06 GMT Indexed on 2010/12/06 16:57 UTC
Read the original article Hit count: 313

Filed under:
|
|

Sometimes I feel stupid about discovering .NET features that have been there since an old release (2.0 in this case)...

Apparently you can just use this configSecion “mailSettings” and never have to configure your SmtpClient instance in code again (no, not hard-coded):

<system.net>
    <
mailSettings
>
        <
smtp deliveryMethod="Network" from="My Display Name &lt;[email protected]&gt;"
>
            <
network host="mail.server.com"
/>
        </
smtp
>
    </
mailSettings
>
</
system.net
>

Now you can go all like:

new SmtpClient().Send(mailMessage);

…and everything is configured for you, even the from address (which you can obviously override).

© ASP.net Weblogs or respective owner

Related posts about .NET

Related posts about configuration