【问题标题】:The server response was: Authentication required even though authentication is provided服务器响应是:即使提供了身份验证,也需要身份验证
【发布时间】:2021-01-06 17:02:24
【问题描述】:

IONOS 没有帮助。尤其是突然之间,表单停止发送电子邮件。

This文章很好的解释和帮助Sending email from webform using SMTP server

我得到的错误是相同的:SMTP 服务器需要安全连接或客户端未通过身份验证。服务器响应是:需要身份验证

这是我的 VB - 我接受了这里的建议,并将 From 与身份验证相同,但仍然没有运气。最初是objMM.From = New MailAddress(txtEmail.Text)。我也确实读过端口 25 可以工作,但这也不起作用。原来是587

Sub btnSendFeedback_Click(sender as Object, e as EventArgs)

'Create an instance of the MailMessage class
Dim objMM as New MailMessage()

'Set the properties - send the email to the person who filled out the
'feedback form.
objMM.To.Add("receiver@receiver.com")
objMM.From = New MailAddress("website@domain.co.uk")

'Send the email in text format
objMM.IsBodyHtml = False

'Set the priority - options are High, Low, and Normal
objMM.Priority = MailPriority.Normal

'Set the subject
objMM.Subject = "Subject"

'Set the body
objMM.Body = " various long boring fields here . . . "

Dim smtp As New SmtpClient()
    smtp.Host = "smtp.ionos.com"
    smtp.EnableSsl = True
    smtp.UseDefaultCredentials = False
    smtp.Credentials = New Net.NetworkCredential("website@domain.co.uk", "passwordhere")
    smtp.UseDefaultCredentials = True
    smtp.Port = 587

'Send method of the SmtpMail class
smtp.Send(objMM)

End Sub 

我想知道这里还有什么问题吗? IONOS 确定这是脚本问题。

【问题讨论】:

  • 如果您使用的凭据不是来自 CredentialCache 的 DefaultNetworkCredentials(发送电子邮件时很有可能),您只需设置 [object].Credentials = new NetworkCredentials(...)UseDefaultCredentials 默认为false,所以不需要设置。如果这样做,您还将重置 Credentials 属性值,无论之前的值是否为默认值。这同样适用于UseDefaultCredentials = true:您正在清除刚刚设置的Credentials。因此,只需设置 Credentials 属性即可。

标签: vb.net


【解决方案1】:

fine manual for SmtpClient.Credentials 说:

某些 SMTP 服务器要求在服务器代表其发送电子邮件之前对客户端进行身份验证。要使用您的默认网络凭据,您可以将 UseDefaultCredentials 设置为 true,而不是设置 [smtpClient.Credentials] 属性。如果 UseDefaultCredentials 属性设置为 false,则在连接到服务器时将使用 Credentials 属性中设置的值作为凭据。如果 UseDefaultCredentials 属性设置为 false 并且尚未设置 Credentials 属性,则将邮件匿名发送到服务器

因此,我希望您的代码仅包含一次提及 UseDefaultCredentials,以便将其设置为 False..

当然,除非您将这些相同的凭据配置为 CredentialCache 中的默认凭据。在这种情况下,在这里再次提及它们是多余的

【讨论】:

    猜你喜欢
    • 2017-08-28
    • 2020-12-02
    • 1970-01-01
    • 2013-09-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多