How to send mail in asp.net using c# without password

To send an email in ASP.NET using C# without a password, you can use the System.Net.Mail namespace and the SmtpClient class. Here's an example:

using System.Net.Mail;

// Create a new SmtpClient object
SmtpClient client = new SmtpClient();

// Set the SMTP server and port
client.Host = "your_smtp_server";
client.Port = 587; // or 25, depending on your SMTP server

// Set the sender's email address
MailAddress from = new MailAddress("your_email_address");

// Set the recipient's email address
MailAddress to = new MailAddress("recipient_email_address");

// Create a new MailMessage object
MailMessage message = new MailMessage(from, to);

// Set the subject and body of the email
message.Subject = "Test email";
message.Body = "This is a test email sent using ASP.NET";

// Send the email
client.Send(message);

In this example, you don't need to specify a password for the SMTP server. Instead, you can use the SmtpClient class's EnableSsl property to enable SSL/TLS encryption, which is often required by SMTP servers.

If your SMTP server requires authentication, you can use the SmtpClient class's Credentials property to specify the username and password. However, if you don't want to hardcode the password in your code, you can use a configuration file or a secure storage mechanism to store the password.

Here's an example of how you can use a configuration file to store the password:

<appSettings>
    <add key="SmtpPassword" value="your_smtp_password" />
</appSettings>

// In your code
SmtpClient client = new SmtpClient();
client.Credentials = new NetworkCredential("your_smtp_username", ConfigurationManager.AppSettings["SmtpPassword"]);

Alternatively, you can use a secure storage mechanism like a secure string or a key vault to store the password.

It's also important to note that sending emails without a password can be a security risk, as it allows anyone with access to your code to send emails on your behalf. Therefore, you should take steps to secure your code and prevent unauthorized access to your email account.