• Dear Pleskians! The Plesk Forum will be undergoing scheduled maintenance on Monday, 7th of July, at 9:00 AM UTC. The expected maintenance window is 2 hours.
    Thank you in advance for your patience and understanding on the matter.

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("admin@mydomain.com");
var toAddress = new MailAddress("example@gmail.com");
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