.NET and SMTP Configuration
- by koevoeter
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 <[email protected]>"> <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).