Utilizing SSL SMTP with .NET Framework
To send emails securely via SSL SMTP with port 465 using the .NET Framework, adhere to the following steps:
Establish a New SmtpClient Object: Create an instance of System.Net.Mail.SmtpClient and configure the connection:
<code class="c#">System.Net.Mail.SmtpClient _SmtpServer = new System.Net.Mail.SmtpClient("tempurl.org"); _SmtpServer.Port = 465; _SmtpServer.EnableSsl = true;</code>
Provide Authentication Credentials: Set authentication credentials for the server:
<code class="c#">_SmtpServer.Credentials = new System.Net.NetworkCredential("username", "password");</code>
Disable Default Credentials and Set Timeouts: Prevent automatic use of the system's credentials and define the timeout period:
<code class="c#">_SmtpServer.UseDefaultCredentials = false; _SmtpServer.Timeout = 5000;</code>
Compose and Send the Email: Prepare the mail message and send it using the _SmtpServer object:
<code class="c#">MailMessage mail = new MailMessage(); mail.From = new MailAddress(from); mail.To.Add(to); mail.CC.Add(cc); mail.Subject = subject; mail.Body = content; mail.IsBodyHtml = useHtml; _SmtpServer.Send(mail);</code>
The above is the detailed content of How to Send Emails Securely with SSL SMTP using .NET Framework?. For more information, please follow other related articles on the PHP Chinese website!