venus najad

venus najad

  • 1.3k
  • 414
  • 28.1k

How activate send email from any email address in c# asp net webform?

Feb 5 2024 6:20 PM

hello everybody

i have created contact us form, but when i send an email from email address, it doesnt work???!!! my codes are as bellow:

btnSend.Enabled = false;
                MailMessage message = new MailMessage(txtEmail.Text, "[email protected]", txtSubject.Text, txtBody.Text); //creates a mail message
                message.IsBodyHtml = true;
                SmtpClient client = new SmtpClient("smtp.gmail.com", 587); //"smtp-mail.outlook.com"
                client.EnableSsl = true;
                client.Credentials = new NetworkCredential(txtEmail.Text, txtPassword.Text);
                client.Send(message);
                lblResult.Text = "your mail has been sent successfully!";
            }
            catch { lblResult.Text = "there was an error.\r\n make sure that your internet is connected"; }
            finally { btnSend.Enabled = true; }//either successful or not enables the send button

appreciate your help with codes or corrections


Answers (12)