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

被折叠的 条评论
为什么被折叠?



