Adhikar Patil

Adhikar Patil

  • NA
  • 481
  • 127.6k

How to Send Email Without using password in Asp.Net

Oct 29 2018 5:46 AM
Hi,
      Can you give me solutions for How to send email without password in Asp.Net. Below is my code
 
   
string to = "[email protected]";
string from = "[email protected]";
MailMessage message = new MailMessage(from, to);
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append("<table>");
sb.AppendFormat("<tr><td>Name:</td><td>{0}</td></tr>", txtName.Text.Trim());
sb.AppendFormat("<tr><td>Email:</td><td>{0}</td></tr>", txtEmail.Text.Trim());
sb.AppendFormat("<tr><td>Phone No</td><td>{0}</td></tr>", txtPhoneNo.Text.Trim());
sb.AppendFormat("<tr><td>Organisation:</td><td>{0}</td></tr>", txtOrganisation.Text.Trim());
sb.Append("<table>");
message.Subject = "BDS Contacted by " + txtName.Text;
message.Body = sb.ToString();
//message.BodyEncoding = Encoding.UTF8;
message.IsBodyHtml = true;
SmtpClient client = new SmtpClient("smtp.gmail.com", 587);
System.Net.NetworkCredential basicCredential1 = new
client.EnableSsl = true;
client.UseDefaultCredentials = false;
client.Credentials = basicCredential1;
try
{
client.Send(message);
}
catch (Exception ex)
{
throw ex;
}

Answers (1)