In this tutorial, I'll show you how to send a email using smtp gmail in C#.NET
Open your app.config file, then add the following code to configuration your email account
<system.net>
<mailSettings>
<smtp from="[email protected]">
<network host="smtp.gmail.com" port="587" userName="[email protected]" password="enter-your-password" enableSsl="true" />
</smtp>
</mailSettings>
</system.net>
Next, We will use the MailMessage class to send an email
MailMessage mailMessage = new MailMessage {
Subject = "c-sharpcode",
Body = "Programming Tutorials"
};
mailMessage.To.Add("[email protected]");
using (SmtpClient smtp = new SmtpClient()) {
smtp.Send(mailMessage);
}
As you know, MailMessage class represents the email we want to send via SMTP