peter

peter

  • 0
  • 159
  • 0

sending email to smtp via Visual Studio developer

Jul 25 2021 9:16 PM

 I am attempting to deliver a email message when i run my webform page to my personal email server address at Yahoo named dog@yahoo.co.uk using my visual studio developer connected to internet. I am unable to succesfully send a message?

 

protected void btnSendEmail_Click(object sender, EventArgs e)
    {
        try
        {
            MailMessage message = new MailMessage();
            SmtpClient smtp = new SmtpClient();
            message.From = new MailAddress("dog@yahoo.co.uk");
            message.To.Add(new MailAddress("peter@yahoo.co.uk"));
            message.Subject = "Test";
            message.IsBodyHtml = true; //to make message body as html  
            message.Body = "";
            smtp.Port = 587;
            smtp.Host = "smtp.mail.yahoo.com"; //for gmail host  
            smtp.EnableSsl = true;
            smtp.UseDefaultCredentials = false;
            smtp.Credentials = new NetworkCredential("dog@yahoo.co.uk", "testbedemail");
            smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
            smtp.Send(message);
        }
        catch (Exception) { }
    }
 


Answers (10)