send email

cardmaker

Member
Joined
Jan 12, 2019
Messages
21
Programming Experience
Beginner
hi, im trying to send a email.
ii already try many codes but no one works.
C#:
try
            {
                MailMessage mail = new MailMessage();
                SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");

                mail.From = new MailAddress("your_email_address@gmail.com");
                mail.To.Add("email@gmail.com");
                mail.Subject = "Test Mail";
                mail.Body = "This is for testing SMTP mail from GMAIL";

                SmtpServer.Port = 587;
                SmtpServer.Credentials = new System.Net.NetworkCredential("my username", "password");
                SmtpServer.EnableSsl = true;

                SmtpServer.Send(mail);
                MessageBox.Show("mail Send");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }

i get "Authentication required" what can be wrong?
 
If you have two-factor authentication turned on you can generate an app password for login in Google account settings.
 
I'm certain there is a bug in this class which is still in need of fixing thus makes it obsolete and not recommended to use by Microsoft, and also thus not allow users to connect using a variety of protocols. But, double check that, as I may be mixing it up with something else, although I'm pretty sure I'm not.

I investigated... and

From Microsoft :
We don't recommend that you use the SmtpClient class for new development because SmtpClient doesn't support many modern protocols. Use MailKit or other libraries instead. For more information, see SmtpClient shouldn't be used on GitHub.

Reference : SmtpClient Class (System.Net.Mail)
 

Latest posts

Back
Top Bottom