[ACCEPTED]-How do I use TLS email with web.config-asp.net

Accepted answer
Score: 29

Its actually equivalent - TLS is kinda of 3 broader than SSL. So use enableSsl= "true" for enabling TLS. As 2 per MSDN documentation, that will force SMTPClient to use 1 RFC 3207 (and RFC uses both terms TLS/SSL).

<network enableSsl="true" host="smtp.gmail.com" port="587" ...
Score: 1

TLS (Transport Level Security) is the slightly 22 broader term that has replaced SSL (Secure 21 Sockets Layer) in securing HTTP communications. So 20 what you are being asked to do is enable 19 SSL.

There is no setting in Web.Config for 18 System.Net.Mail (.net 2.0) that maps to 17 EnableSSL property of System.Net.Mail.SmtpClient.

Resolution

1) In 16 the code behind, We need to consume PasswordRecovery1_SendingMail 15 event of the web control
2) This event provide 14 us access to Email Message being sent and 13 also give us option to cancel the send operation
3) We 12 will make a copy of this email message, and 11 create a new instance of System.Net.Mail.SmtpClient
4) This 10 time we have complete access to its properties 9 and we can turn On/Off the EnableSSL setting
5) Lets 8 set EnableSSL to true and send the email 7 message to desired SMTP server

The below 6 code snippet can do the job.

protected void PasswordRecovery1_SendingMail(object sender, MailMessageEventArgs e)
{
System.Net.Mail.SmtpClient smtpSender = new System.Net.Mail.SmtpClient("mail.google.com", 587);
smtpSender.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
smtpSender.Credentials = new System.Net.NetworkCredential("username@gmail.com", "password");
smtpSender.EnableSsl = true;

smtpSender.Send(e.Message);
e.Cancel = true;
}

Repro Steps

1) Configure 5 a PasswordRecovery control
2) Provide all 4 the settings in Web.Config, including username/password, server 3 name, email sender and others
3) Try to 2 send a recovery email when SMTP server requires 1 SSL

Check below link:
http://blogs.msdn.com/b/vikas/archive/2008/04/29/bug-asp-net-2-0-passwordrecovery-web-control-cannot-send-emails-to-ssl-enabled-smtp-servers.aspx

More Related questions