How to add system.web.mail in c
A classic question!
To use the System.Web.Mail
namespace in C#, you'll need to add a reference to the System.Web
assembly and import the namespace in your code.
Here are the steps:
Step 1: Add a reference to the System.Web
assembly
In Visual Studio, right-click on your project in the Solution Explorer and select "Add Reference". In the Reference Manager dialog box, navigate to the "Assemblies" tab and check the box next to "System.Web". Click "OK" to add the reference.
Step 2: Import the System.Web.Mail
namespace
In your C# code file, add the following line at the top:
using System.Web.Mail;
This imports the System.Web.Mail
namespace, which provides classes for sending email messages.
Step 3: Use the System.Web.Mail
classes
You can now use the classes in the System.Web.Mail
namespace to send email messages. For example:
using System.Web.Mail;
// Create a new MailMessage object
MailMessage mail = new MailMessage();
// Set the sender and recipient
mail.From = "[email protected]";
mail.To = "[email protected]";
// Set the subject and body
mail.Subject = "Test email";
mail.Body = "This is a test email";
// Send the email using the SmtpMail class
SmtpMail.Send(mail);
Note that the SmtpMail
class is used to send the email message using an SMTP server. You'll need to configure the SMTP server settings in your code or in the web.config file.
That's it! With these steps, you should be able to use the System.Web.Mail
namespace in your C# code to send email messages.