SmtpClient“请求失败;邮箱不可用”

时间:2018-05-25 17:14:11

标签: c# asp.net-mvc email smtp

我试图在yahoo smtp服务器上发送和使用SmtpClient发送电子邮件

  

“smtp.mail.yahoo.com”,587

第一次尝试时,我收到一封电子邮件,告诉我更改我的帐户设置以允许smtp请求正常工作,但在此之后,邮箱不可用。

SendMail方法:

public void SendMail(string name, string from, string to, string subject, string content)
    {
        try
        {
            using (var mail = new MailMessage())
            {
                const string email = @"mail@yahoo.com";
                const string pw = "***";

                var login = new NetworkCredential(email, pw);

                mail.From = new MailAddress(from);
                mail.To.Add(new MailAddress(to));
                mail.Subject = subject;
                mail.Body = content;
                mail.IsBodyHtml = true;

                try
                {
                    using (var client = new SmtpClient("smtp.mail.yahoo.com", 587))
                    {
                        client.EnableSsl = true;
                        client.DeliveryMethod = SmtpDeliveryMethod.Network;
                        client.UseDefaultCredentials = false;
                        client.Credentials = login;
                        client.Send(mail);
                    }
                }
                finally
                {
                    mail.Dispose();
                }
            }
        }
        catch(Exception ex)
        {

        }
    }

动作:

[HttpPost]
    public ActionResult ContactSend(Mail mail)
    {
        if(ModelState.IsValid)
        {
            var toAdress = @"tomail@yahoo.de";
            var fromAdress = mail.Email;
            var subject = mail.Betreff;
            var name = mail.Name;
            var content = new StringBuilder();
            content.Append("Name: " + name + "\n");
            content.Append("Email: " + fromAdress + "\n\n");
            content.Append(mail.Content);

            SendMail(name, fromAdress, toAdress, subject, content.ToString());

        }

        return RedirectToAction("Kontakt", "Home");
    }

检查了所有的登录信息,因为我第一次尝试时收到了来自雅虎的电子邮件,他们似乎工作了。

例外:

  • Response {System.Web.HttpResponseWrapper} System.Web.HttpResponseBase {System.Web.HttpResponseWrapper}
  • ex {“Postfachnichtverfügbar.DieServerantwort war:Request failed; Mailbox unavailable”} System.Exception {System.Net.Mail.SmtpException}
  • Data {System.Collections.ListDictionaryInternal} System.Collections.IDictionary {System.Collections.ListDictionaryInternal}     HResult -2146233088 int     HelpLink null string
  • InnerException null System.Exception     消息“Postfachnichtverfügbar.DieServerantwort war:请求失败;邮箱不可用”字符串     源“系统”字符串     StackTrace“bei System.Net.Mail.MailCommand.CheckResponse(SmtpStatusCode statusCode,String response)\ r \ n bei System.Net.Mail.MailCommand.Send(SmtpConnection conn,Byte [] command,MailAddress from,Boolean allowUnicode)\ r \ n \ n bei System.Net.Mail.SmtpTransport.SendMail(MailAddress sender,MailAddressCollection recipients,String deliveryNotify,Boolean allowUnicode,SmtpFailedRecipientException& exception)\ r \ n bei System.Net.Mail.SmtpClient.Send(MailMessage message)\ r \ n bei Makler.Controllers.HomeController.SendMail(String name,String from,String to,String subject,String content)在C:\ Users \ Joshua \ source \ repos \ Makler \ Makler \ Controllers \ HomeController.cs:Zeile 90。 “串     StatusCode MailboxUnavailable System.Net.Mail.SmtpStatusCode
  • TargetSite {Void CheckResponse(System.Net.Mail.SmtpStatusCode,System.String)} System.Reflection.MethodBase {System.Reflection.RuntimeMethodInfo}
  • 静态成员
  • 非公开会员
  • this {Makler.Controllers.HomeController} Makler.Controllers.HomeController

1 个答案:

答案 0 :(得分:0)

“邮箱不可用”是来自雅虎邮件服务器的邮件,但除了他们不想与您交谈外,意味着很少。

“收件人:”地址可能超出空间或拼写错误,或者他们可能不喜欢您的IP地址或其他任何一件事。

您可以谷歌获取雅虎邮件管理员帮助,看看他们是否有任何建议。

您已成功连接,但他们拒绝接受您的邮件。您需要实际信息才能知道原因。

相关问题