Help with code that fails to send email RRS feed

  • Question

  • below code fails to send mail

                email = tbFROM.Text;
                passw = tbPASSWORD.Text;
                string smtpAddress = "";
                int portNumber = 587;
                bool enableSSL = true;
                string emailFromAddress = email; //Sender Email Address  
                string password = passw; //Sender Password  
                string emailToAddress = email; //Receiver Email Address  
                string subject = "Hello";
                string body = "Hello, This is Email sending test using gmail.";
                using (MailMessage mail = new MailMessage())
                    mail.From = new MailAddress(emailFromAddress);
                    mail.Subject = subject;
                    mail.Body = body;
                    mail.IsBodyHtml = true;
                    //mail.Attachments.Add(new Attachment("D:\\TestFile.txt"));//--Uncomment this to send any attachment  
                    using (SmtpClient smtp = new SmtpClient(smtpAddress, portNumber))
                        smtp.Credentials = new NetworkCredential(emailFromAddress, password);
                        smtp.EnableSsl = enableSSL;

    one below also fails to send email

                email = tbFROM.Text;
                passw = tbPASSWORD.Text;
                //MailMessage mail = new MailMessage(tbFROM.Text,tbTO.Text,tbSUBJECT.Text,rtbBODY.Text);
                MailMessage mail = new MailMessage(email,email,email,email);
                SmtpClient smtpClient = new SmtpClient("");
                smtpClient.Port = 587;
                //smtpClient.Credentials = new NetworkCredential(tbUSERNAME.Text,tbPASSWORD.Text);
                smtpClient.Credentials = new NetworkCredential(email,passw);
                smtpClient.EnableSsl = true;

    google fails to to SEND EMAIL??

    Sunday, May 19, 2019 10:41 AM

All replies

  • The first thing you should do is provide the error message received on failure to send an email. If an error message is not presented (which it should be) subscribe to SendCompleted event and inspect e.Error.

    Login to your Google email account to the follow page, if "Less secure app access" is off, try setting this setting to on then reattempt to send an email.

    See also, "what are the dangers of allowing less secure apps".

    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    profile for Karen Payne on Stack Exchange

    • Proposed as answer by zarahhhh Thursday, May 23, 2019 9:19 AM
    Sunday, May 19, 2019 11:17 AM
  • Hi okardak onur,

    Thank you for posting here.

    Gmail have already upgraded their security authentication system, more steps are required to successfully log into their mail server using programing code.

    Based on my search, you could try the examples in the link below.

    Best Regards,


    Note: This response contains a reference to a third-party World Wide Web site. Microsoft is providing this information as a convenience to you. 
    Microsoft does not control these sites and has not tested any software or information found on these sites; Therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there.
    There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet. 

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    • Proposed as answer by zarahhhh Thursday, May 23, 2019 9:19 AM
    Monday, May 20, 2019 5:40 AM
  • what is paypal microsoft account to pay money for help?
    Wednesday, June 5, 2019 10:36 AM