• If you are still using CentOS 7.9, it's time to convert to Alma 8 with the free centos2alma tool by Plesk or Plesk Migrator. Please let us know your experiences or concerns in this thread:
    CentOS2Alma discussion

Sending mail with ASP.NET

Z

Zoltan

Guest
Hello,

I want to send a confirmation mail to my users. I'm using ASP.NET MVC 2 and this is my code:

var fromAddress = new MailAddress("[email protected]");
var toAddress = new MailAddress("[email protected]");
const string fromPassword = "xxxxxxxxx";
string subject = "test";
string body = "test text";
var smtp = new SmtpClient
{
Host = "mail.mydomain.com",
Port = 25,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
Credentials = new NetworkCredential(<a user account with administrator role created in plesk>, <the user's password>)
};
using (var message = new MailMessage(fromAddress, toAddress)
{
Subject = subject,
Body = body
})
{
smtp.Send(message);
}

But I receive this exception when executing the above code:
Bad sequence of commands. The server response was: This mail server requires authentication when attempting to send to a non-local e-mail address. Please check your mail client settings or contact your administrator to verify that the domain or address is defined for this server.

Thanks in advance
 
I have authenticated as you can see in my code:

Credentials = new NetworkCredential(<a user account with administrator role created in plesk>, <the user's password>)
 
What kind of mail Server used by SmtpClient class?
You are able to switch to this mail server: Home>Tools & Settings>Server Components>Select default Webmail component
 
Last edited:
Thank you for your help. The problem was in the settings of the SMTP server. It was configured to deny relay from any incoming IP!
I've found the solution here
 
Back
Top