asp.net2.0 发送email的helper,附带详细注释。
下面是局域网内发送邮件,可以匿名发送
下面是通过本机(IIS自带的smtp服务器)发送,没有身份验证。
这个其实也很有用,通常来说,实际工作当中会遇到开发企业内部的web应用程序(比如说OA),那么就得使用内部的smtp服务器了。
只可惜,搞了一下午也没有通过测试。(不能中继到internet)
protected void SendFromLocal_Click(object sender, EventArgs e)
{
string to = "xxxx@163.com";
string from = "xxxx@163.com";
string subject = MailTitle.Text;// "Using the new SMTP client.";
string body = MailBody.Text;// @"Using this new feature, you can send an e-mail message from an application very easily.";
MailMessage message = new MailMessage(from, to, subject, body);
SmtpClient client = new SmtpClient("localhost", 25);
// Credentials are necessary if the server requires the client
// to authenticate before it will send e-mail on the client's behalf.
client.Credentials = CredentialCache.DefaultNetworkCredentials;
client.Send(message);
}
通过本机发送的时候,可能会出现"邮箱不可用"的问题。 服务器响应为: 5.7.1 Unable to relay for xxxx@163.com"
解决办法:
在IIS中,右击“默认SMTP虚拟服务器”,选择“属性”,切换到“访问”页,点击“中继”按钮,在弹出框中选择“仅以下列表除外”,确定。