Thursday, June 21, 2007

Send an email by GMail from ASP.NET 2.0

If you try to use ChangePassword control with GMail server in your settings, you'll probably get failed. To fix that you need to use SSL to send an email, and also - set SMTP server port to 587.

To use SSL add a handler to SendingMail event of the control with the following body:

protected void _ctrlPasswordRecovery_SendingMail(object sender, MailMessageEventArgs e)

{

        // send the same email, but with SSL enable

    SmtpClient client = new SmtpClient();

    client.EnableSsl = true;

    client.Send(e.Message);

 

        // cancel the sending by control

    e.Cancel = true;

}

Labels: , , , , ,