Click here to Skip to main content
15,867,906 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,Friends i have a problem to sending smtp.gmail directly email plz some one help me, i don't know where i m doing mistake and get this error.

C#
The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required

==========================================================================

C#
private void SendEmail(string client, string clientemail, ArrayList orderList)
    {
        try
        {
            //SET UP SENDER AND RECEIVER E-MAIL ADDRESSES
            MailAddress to = new MailAddress(clientemail);

            //TODO: Fill in your own e-mail here!
            MailAddress from = new MailAddress("myemail@hotmail.com");
            // SET UP EMAIL BODY///
            StringBuilder sb = new StringBuilder();
            sb.AppendFormat(@"
Dear {0}
We are happy to announce that your order placed on {1} has been completed and is ready for pickup.

Your ordered products:", client, Request.QueryString["date"]);
            double total = 0;
            foreach (Order order in orderList)
            {
                sb.AppendFormat(@"
- {0} ({1} €)           X {2}                 = {3}", order.Product, order.Price, order.Amount, (order.Amount * order.Price));
                total += (order.Amount * order.Price);
            }
            sb.Append(@"
Total amount=" + total);
            sb.Append(@"
You can come to receive your order at your earliest convenience.
Kind regards");
            // set up mail credentials
            MailMessage mail = new MailMessage(from, to);
            mail.Body = sb.ToString();
            mail.Subject = "Your order has been completed";
            // set up SMTP credentials
            SmtpClient smtp = new SmtpClient();
            smtp.Host = "smtp.gmail.com";
            smtp.EnableSsl = true;
            //TODO: Fill in your own e-mail and password here!
            smtp.Credentials = new NetworkCredential("myemail@hotmail.com", "mypassword");
            smtp.UseDefaultCredentials = true;
            //smtp.Credentials = NetworkCred;
            smtp.Port = 587;
            // send email
            smtp.Send(clientemail);
Posted
Comments
Jochen Arndt 26-Jan-16 13:29pm    
Are you trying to authenticate with an hotmail account at GMail?
That won't work.
Or is just an example?
Member 10267889 14-Feb-16 15:45pm    
Thanks sir, for your help i was doing little mistake now is every thing ok thanks a lot once again
Kevin Marois 26-Jan-16 13:29pm    
Try setting smtp.UseDefaultCredentials = false
Member 10267889 14-Feb-16 15:47pm    
Sir, I solve this problem thanks a lot for help.

1 solution

 
Share this answer
 
Comments
Member 10267889 27-Jan-16 13:44pm    
I tried it but still problem is remaining.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900