The error message is saying your mail server requires authentication. While there are many ways to achieve this, you can create a new NetworkCredential
object and supply that to your mailmessage named parameters:
public static void SendEmailWebService(string asunto, string body, string to)
{
try
{ // takes config from web.config
MailMessage mm = new MailMessage
{
From = new MailAddress(@"no-reply@site.com", @"Notificacion"),
To = { new MailAddress(to) },
Subject = asunto,
IsBodyHtml = true,
Body = body,
HeadersEncoding = System.Text.Encoding.UTF8,
SubjectEncoding = System.Text.Encoding.UTF8,
BodyEncoding = System.Text.Encoding.UTF8,
UseDefaultCredentials = false,
Credentials = new NetworkCredential("username", "password")
};
Smtp.Send(mm);
}
catch (Exception ex)
{
// Error
}
}
If you don't want to add the NetworkCredential
to your source code you can also configure it from the web.config file
<system.net>
<mailSettings>
<smtp>
<network host="" port="" userName="" password=""/>
</smtp>
</mailSettings>
</system.net>