Reputation: 32612
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:
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:
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>
How to send it without authentication?
Upvotes: 15
Views: 52025
Reputation: 13680
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.
Upvotes: 30