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:
But I receive this exception when executing the above code:
Thanks in advance
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