I am trying to design a 'Contact Us' page using ASP.NET and C#.
Here is my code-behind the 'Send' button:
try
{
if (Page.IsValid)
{
MailMessage mailMessage = new MailMessage();
mailMessage.From = new MailAddress("SENDER@gmail.com");
mailMessage.To.Add("RECEIVER@gmail.com"); //can have multiple here
mailMessage.Subject = txtSubject.Text;
mailMessage.Body = "<b>Sender Name:</b>" + txtName.Text + "<br/>"
+ "<b>Sender Email:</b>" + txtEmail.Text + "<br/>"
+ "<b>Comments:</b>" + txtComments.Text;
//for the HTML tags mentioned in the body above
mailMessage.IsBodyHtml = true;
//IN THE TUTORIAL, HE IS USING GMAIL'S SMTP SERVER:
SmtpClient smtpClient = new SmtpClient("smtp.gmail.com", 587);
smtpClient.EnableSsl = true;
smtpClient.Credentials =
new System.Net.NetworkCredential("SENDER@gmail.com", "PASSWORD");
smtpClient.Send(mailMessage);
Label1.Text = "Thank you for contacting us";
Label1.ForeColor = System.Drawing.Color.Blue;
txtName.Enabled = false;
txtEmail.Enabled = false;
txtComments.Enabled = false;
txtSubject.Enabled = false;
Button1.Enabled = false;
}
}
catch (Exception ex)
{
// Log - Event Viewer or table
Label1.ForeColor = System.Drawing.Color.Red;
Label1.Text = "There is an unknown problem. Please try later";
}
In the tutorial which I followed, you need to assignthe sender's email & password to the smtpClient.Credentials.
Is there a way to submit this email without having to know the sender's password?