smtpClient发邮件错误:不允许使用邮箱名称。 服务器响应为: You are not authorized to send mail, authentication is required

本文详细介绍了在使用Asp.Net2.0通过Sina SMTP发送邮件时遇到的认证错误问题,并提供了解决方案。主要涉及如何正确配置SMTP客户端以解决邮件发送时出现的'You are not authorized to send mail, authentication is required'错误,特别是针对163邮箱的特定注意事项。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

Asp.Net 2.0 使用 System.Net.Mail.SmtpClient发送邮件时,提示错误:

 smtpClient发邮件错误:不允许使用邮箱名称。 服务器响应为: You are not authorized to send mail, authentication is required

 

发现原来是指定Credential时,163的smtp只需要指定用户名即可,无需指定完整的Email地址。

 


 private void SendMail(string fromMail, string toMail, string subject, string body)
        {
            try
            {
                MailAddress from = new MailAddress(fromMail);
                MailAddress to = new MailAddress(toMail);
                MailMessage message = new MailMessage(from, to);
                message.Subject = subject;//设置邮件主题
                message.IsBodyHtml = true;//设置邮件正文为html格式
                message.Body = body;//设置邮件内容
                SmtpClient client = new SmtpClient("smtp.sina.com");
                //设置发送邮件身份验证方式

             //注意如果发件人地址是abc@def.com,则用户名是abc而不是abc@def.com
                client.Credentials = new NetworkCredential(用户名,密码);
                client.Send(message);
            }
            catch(Exception ee)
            {
                throw ee;
            }
        }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值