我正在从 Java 向我们的客户发送电子邮件。而且我们的 SMTP 没有任何身份验证。因此,我在 Java 中使用以下代码无需身份验证即可发送:
Properties props = new Properties();
Session session;
props.put("mail.smtp.auth", "false");
session = Session.getInstance(props, null);
此代码适用于从 Java 发送电子邮件。但我想使用 ASP.NET 和 C# 发送电子邮件。但是我无法发送它。为了使用 C# 发送它,我使用以下代码:
SmtpClient smtp = new SmtpClient();
smtp.Host = "<My smtp.Host>";
smtp.EnableSsl = false;
smtp.Credentials = CredentialCache.DefaultNetworkCredentials;
smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
smtp.Send(message);
但它给了我以下错误:
The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.1 Relaying not allowed:
<Here email address of To>
如何在不认证的情况下发送?
最佳答案
来自 Msdn。 如果 UseDefaultCredentials 属性设置为 false 并且尚未设置 Credentials 属性,则邮件将匿名发送到服务器。
关于c# - SmtpClient 无认证发送,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11719534/