venus najad

venus najad

  • 1.3k
  • 414
  • 27.8k

email domain, contact us in c# webapplication aspnet webform

Aug 4 2024 2:28 PM

hello, i have an issue, contact us in webapplication aspnet webform

i have an advertise website, in which people put their ads and they contact echother by any form of email address. the same when people will contact me with their defaqult email address. in my case, the problem is the client's creditial and host, which must be specific or defined. but how make it default or general?

protected void btnSend_Click(object sender, EventArgs e)
        {                      
            MailMessage message = new MailMessage(txtEmail.Text, emailto, txtSubject.Text, txtBody.Text); //creates a mail message
            message.IsBodyHtml = true;
            
            SmtpClient client = new SmtpClient
            {
                Port = 25, //any client
                Host = "smtp.gmail.com",//"smtp-mail.outlook.com", //"smtp.sendgrid.net", //or another email sender provider
                EnableSsl = true,
                DeliveryMethod = SmtpDeliveryMethod.Network,
                UseDefaultCredentials = true,                
                Credentials = new NetworkCredential("[email protected]", 'my secret password') //but it must be sender, not me
            };

            try
            {
                client.Send(message);
                lblResult.Text = "your mail has been sent successfully!";
            }
            catch (Exception ex) { lblResult.Text = ex.Message; }
            finally { btnSend.Enabled = true; clearFields(); }            
        }

//////////////////////////////////////////////

i used another way, i made droppdownlist with different hosts (what stands after @ sign in email)   and i used 

client.Credentials = new NetworkCredential(txtEmail.Text, txtPassword.Text, domain);

but didn't worked??!!

how should i make default host??!! appreciate your respond, with codes. very kind regards

 


Answers (6)