这里演示如果把 Email provider 的资料写在 WebConfig 里和调用它.
如果整个项目只需要使用一个 Email, 可以写入system.net里, 微软已经帮我们设计好了
<configuration> <system.net> <mailSettings> <smtp deliveryMethod="Network" from="Stooges Web Design Default <[email protected]>"> <network host="mail.stooges.com.my" port="587" userName="[email protected]" password="I(d3pwt3cs" enableSsl="false" /> </smtp> </mailSettings> </system.net> <configuration>
然后简单调用就可以了
SmtpClient smtp = new SmtpClient(); MailMessage mail = new MailMessage { Subject = "subject", Body = "html content", IsBodyHtml = true }; mail.To.Add("[email protected]"); smtp.Send(mail);
时间: 2024-10-30 19:44:08