Sending an email in C# is relatively simple thanks to the System.Net.Mail
namespace. The following code snippet shows a basic example of how to send an email using SMTP:
main.cs440 chars16 lines
In this example, the MailMessage
class is used to create the email message with the sender, recipient, subject, and body. The SmtpClient
class is used to send the email via SMTP. The SMTP server hostname and port number are specified in the SmtpClient
constructor. The EnableSsl
property is set to true to enable SSL encryption if required by the SMTP server. Finally, the Credentials
property is set to the username and password required by the SMTP server for authentication.
Note: Replace "smtp.example.com" with the hostname of your SMTP server and "username" and "password" with your SMTP server credentials.
gistlibby LogSnag