最近在做邮件发送接口 把遇到的问题和解决方法告诉大家 希望对了解邮件的人有所帮助
原程序部分代码如下
//设置邮件信息 发件人地址、收件人地址、标题、主题 MailMessage mail = new MailMessage("xxxxxxx@sina.com", "zzzzzzz@sina.com", "标题", "主题"); //设置邮件主题格式 mail.BodyEncoding = Encoding.UTF8; //设置邮件主体格式是否为 html 格式 mail.IsBodyHtml = false; //验证邮箱用户名 密码 NetworkCredential work = new NetworkCredential("xxxxxxx", "pwd"); //验证 用户名 密码 client.Credentials = work; //设置邮箱smtp服务器 端口 SmtpClient client = new SmtpClient("smtp.sina.com"); //是否请求一起发送 client.UseDefaultCredentials = false; //设置邮件发送格式 client.DeliveryMethod = SmtpDeliveryMethod.Network; //安全连接设置 client.EnableSsl = false; client.Send(mail);</div>
错误一:“/”应用程序中的服务器错误。
SMTP 服务器要求安全连接或客户端未通过身份验证。 服务器响应为: 5.7.1 Client was not authenticated
说明: 执行当前 Web 请求期间,出现未经处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.Net.Mail.SmtpException: SMTP 服务器要求安全连接或客户端未通过身份验证。 服务器响应为: 5.7.1 Client was not authenticated
解决方法 :
//设置邮箱smtp服务器 端口 SmtpClient client = new SmtpClient("smtp.sina.com",587);</div>
解决说明:我加上了端口号,587属于发送邮件端口 一般出现此错误会出现在你设置的163的接受者时发生 QQ的没有问题!
错误二 :“/”应用程序中的服务器错误。
服务器不支持安全连接。
说明: 执行当前 Web 请求期间,出现未经处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.Net.Mail.SmtpException: 服务器不支持安全连接。 我将 //安全连接设置 client.EnableSsl = True;后发生的错误
解决方法 :方法一 设置成“client.EnableSsl = false ”或去掉这句代码
方法二 开启安全连接服务
错误三:SMTP 服务器要求安全连接或客户端未通过身份验证。 服务器响应为: Authentication required
堆栈跟踪: [SmtpException: SMTP 服务器要求安全连接或客户端未通过身份验证。 服务器响应为: Authentication required]
解决方法:
client.EnableSsl = false; 改为 client.EnableSsl = true; 但是这样该后可能会出现“错误二”的提示,所以要解决
这个的话 首先保证服务器是支持安全连接的
错误四:
SMTP 服务器要求安全连接或客户端未通过身份验证。 服务器响应为: 5.7.0 Must issue a STARTTLS command first. 9sm5225813ywf.35
解决方法:sina要求用ssl连接 可以改一下true
万能解决方法:
1、POP3和SMTP服务器要填正确
2、服务器的端口要正确
3、我的服务器要求身份认证
4、发送邮件的用户名和密码要正确
//设置邮箱smtp服务器 端口
SmtpClient client = new SmtpClient("smtp.sina.com",587); 就可以了
163的最固执了!需要注意点 QQ最好过!呵呵
有些时候邮件被退信的原因 提供以下解决方法:
一、FOXMAIL发送邮件常见出错代码:
问题:the server says:550 relaying mail to <> is not allowed
问题:The server says:550 <>... relaying denied
问题:the server says:550 5.7.1 relaying not permitted:
解答:使用某些Smtp服务器时,限制了收件人的地址,只能换一个Smtp服务器。
问题:The server says:550 <>:local user only
问题:The server says:550 <>:Invalid User
问题:The server says:550 Invalid recipient
解答:使用163.net,163.com,yeah.net和netease.com之类的Smtp服务器时,只能用自身的信箱发信,所以要在Outlook Express的“帐户属性”中的“个人信息”里面填写正确的邮件地址。
问题:the server says:551 delivery not allowed to non-local recipient
问题:The server says:553 Relay restriction.
问题:The server says:553 From <>, message blocked.
问题:The server says:553 sorry,you are not allow to use this SMTP to relay your eami
问题:The server says:553 sorry, that domain isn&apost in my list of allowed rcpthosts
解答:使用21cn.com,china.com,371.net,sina.com等大多数信箱的smtp服务器时,只能用自身的信箱发信,所以要在Outlook Express的“帐户属性”中的“个人信息”里面填写正确的邮件地址。
问题:The server says:505 client was not authenticated
问题:The server says:553 authentication is required to send mail as <>
解答:使用263.net和sohu.com的Smtp服务器时,不但要用自身的邮箱发信,而且要加入身份验证,所以即要在“个人信息”中填写正确邮箱地址,又要选中“SMTP服务器需要认证”。
问题:The server says:535 Error:authenticatin failed
问题:The server says:535 Authentication unsuccessful
问题:The server says:452 Insufficient system storage
解答:在使用Esmtp认证的过程中出错,检查一下Esmtp设置,多试几次。
问题:The server says:553 <>...domain name required
问题:The server says:550 Unable to relay for ...
解答:多出现在用Wingate代理服务器发送邮件时。虽然在Wingate中“POP3 邮箱帐号”要使用“用户名#POP3地址”的格式,但在“帐户属性”中的“个人信息”中还是要填写一般的格式。
问题:The server says:553 mailbox name not allowed
解答:收件人邮箱地址不允许,需检查收件人地址是否正确。
问题:the server says:553 sorry, your envelop sender is in my badmailfrom list
解答:服务器限制了收件人的地址,只能换一个smtp服务器发信。
问题:the server says:554 Transaction failed
问题:The server says:451 Requested action aborted,errno=28
解答:传输失败,检查网络问题。
问题:the server says:503 error:needmail command
问题:The server says:503 need mail before RCPT.
问题:The server says:503 Bad sequence of commands
解答:消息命令顺序出错,一般出现在其他错误之后,先检查之前出现的错误提示。
问题:The Server says:501 syntax.helo hostname
问题:The server says:501 Invalid domain name
问题:The server says:502 unimplemented command
问题:the server says:503 5.0.0 polite people say HELO first
问题:The server says:533 relay restriction
问题:The server says:544 <>:Recipient address rejected: Relay access denied
解答:传输中的语法错误,原因不明。
二、OUTL