asp.net2.0 发送email的helper

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虚拟服务器”,选择“属性”,切换到“访问”页,点击“中继”按钮,在弹出框中选择“仅以下列表除外”,确定。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值