Thursday, October 4, 2018

How to send email by using yahoo server in C# code

 try
                {
                    var message = new MailMessage(txtsenderEmail.Text, txtrecEmail.Text);
                    message.Subject = txtSubject.Text;
                    message.Body = rboxBody.Text;
                   
                    using (SmtpClient mailer = new SmtpClient("smtp.mail.yahoo.com", 587))
                    {
                        mailer.Credentials = new NetworkCredential(txtsenderEmail.Text, txtPassword.Text);
                        mailer.EnableSsl = true;
                        mailer.Send(message);

                    }
                   
                    MessageBox.Show("Email succesfull sent", "Message");
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error" + ex, "Message",);
                }
            }

No comments:

Post a Comment