C# SmtpClient 发送未经身份验证

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11719534/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-09 18:57:22  来源:igfitidea点击:

SmtpClient sending without authentication

c#asp.netemailauthenticationsmtpclient

提问by hims056

I am sending emails to our clients from Java. And there is no any authentication for our SMTP. So I use the following code in Java to send it without authentication:

我正在从 Java 向我们的客户发送电子邮件。我们的 SMTP 没有任何身份验证。所以我在Java中使用以下代码在没有身份验证的情况下发送它:

Properties props = new Properties();
Session session;
props.put("mail.smtp.auth", "false");
session = Session.getInstance(props, null);

This code works fine for sending emails from Java. But I want to send emails using ASP.NET and C#. But I am unable to send it. For sending it using C# I am using the following code:

此代码适用于从 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);

But it gives me the following error:

但它给了我以下错误:

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>

SMTP 服务器需要安全连接或客户端未通过身份验证。服务器响应为:5.7.1 不允许中继:<Here email address of To>

How to send it without authentication?

如何在没有身份验证的情况下发送它?

采纳答案by David Anderson

From Msdn. If the UseDefaultCredentials property is set to false and the Credentials property has not been set, then mail is sent to the server anonymously.

来自 msdn。 If the UseDefaultCredentials property is set to false and the Credentials property has not been set, then mail is sent to the server anonymously.