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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With