我是C#的ASP.NET新手。任何人都可以指导我如何使用服务器(包括配置服务器)通过ASP.NET使用C#发送电子邮件。
答案 0 :(得分:4)
using System.Net.Mail;
...
MailMessage message = new MailMessage();
message.From = new MailAddress("sender@foo.bar.com");
message.To.Add(new MailAddress("recipient1@foo.bar.com"));
message.To.Add(new MailAddress("recipient2@foo.bar.com"));
message.To.Add(new MailAddress("recipient3@foo.bar.com"));
message.CC.Add(new MailAddress("carboncopy@foo.bar.com"));
message.Subject = "This is my subject";
message.Body = "This is the content";
SmtpClient client = new SmtpClient();
client.Send(message);
web.config中的
<system.net>
<mailSettings>
<smtp from="test@foo.com">
<network host="smtpserver1" port="25" userName="username" password="secret" defaultCredentials="true" />
</smtp>
</mailSettings>
感谢Scott