protected void Button1_Click(object sender, EventArgs e)
{
MailMessage message = new MailMessage()
{
Subject = "Subject",
Body = "Body"
};
message.To.Add(new MailAddress("demo@example.com", "Some name"));
SmtpClient client = new SmtpClient();
client.EnableSsl = true;
client.Send(message);
}
config
<configuration>
<system.net>
<mailSettings>
<smtp from="demo@example.com">
<network host="****" defaultCredentials="false" port="587" userName="****" password="****" />
</smtp>
</mailSettings>
</system.net>
<system.web>
Correction. it works now. Thanks Marek
Your problem might be with
defaultCredentialsset to true. Try setting that to false and try again. Also, why are you setting your credentials again in code? Gmail also requires emails to be sent via SSL (if I remember correctly) on port 587.Just today I implemented gmail smtp in my code. My settings and code: