2012-07-30 64 views
8

我从Java向我们的客户发送电子邮件。并且我们的SMTP没有任何身份验证。所以我在Java中使用以下代码发送它而不进行身份验证:SmtpClient无需身份验证发送

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>

如何在没有验证发送?

回答

19

来自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.

+0

我不明白。我应该设置哪个属性来发送它,而无需身份验证? – hims056 2012-07-30 10:34:47

+0

完全删除'smtp.Credentials = ...',并将UseDefaultCredentials设置为false。 – 2012-07-30 10:37:50

+1

哦..试过但给出了同样的错误。 – hims056 2012-07-30 10:41:40

相关问题