Hi all,
i am developing web application, so if users want to use this application,first they should be register their details,at the time i have to send Userid and password to their Email address.now i'm have a code but it is not working,i got one error from this code.
the error is " SMTP Exception was caught: The SMTP Server requiers a secure connection or the client was not authenticated. the server response was :5.5.1 Authentication required ".
And also i attached my code.
Please help me anyone.,

Thank you

public Boolean SendMail(String mailId, String mailBody)
    {
        try
        {

            System.Net.Mail.MailMessage message;
            message = new System.Net.Mail.MailMessage("\"Twaik Group\" <mmmm@gmail.com>", mailId, "Company name", mailBody);
            message.Priority = MailPriority.High;
            message.IsBodyHtml = true;

            //SmtpClient client = new SmtpClient("173.248.137.38");
            SmtpClient client = new SmtpClient();
            client.Host = "smtp.gmail.com";
            client.Port = 25;
            client.EnableSsl = true;
            client.DeliveryMethod = SmtpDeliveryMethod.Network;
            client.UseDefaultCredentials = false;
            client.Credentials = new System.Net.NetworkCredential("mmmm@gmail.com", "***********");


            client.Send(message);
            return true;
        }
        catch
        {
            return false;

        }
    }

Found this code in another post and it works for me:

MailMessage Message = new MailMessage();
Message.To.Add("******@gmail.com");
Message.From = new MailAddress("NewUser@somewhere.com", "New User", Encoding.UTF8);
Message.Subject = "Test";
Message.SubjectEncoding = Encoding.UTF8;
Message.Body = "Test";
Message.BodyEncoding = Encoding.UTF8;
Message.IsBodyHtml = false;
Message.Priority = MailPriority.High;
SmtpClient client = new SmtpClient("smtp.gmail.com");
client.Credentials = new NetworkCredential("******@gmail.com", "******");
client.Port = 587;
client.Host = "smtp.gmail.com";
client.EnableSsl = true;
client.Send(Message);

thank you Mr.tinstaafl., now its working...

You're very welcome. Please remember to mark this solved thanks.

Here is an example

MailMessage mailMessage = new MailMessage(new MailAddress("sender@email.com", "Sender Name"), new MailAddress("email@email.com"));
mailMessage.Subject = "Some subject";
mailMessage.Body = msg;
mailMessage.IsBodyHtml = true;
SmtpClient smtpClient = new SmtpClient();
smtpClient.Send(mailMessage);

Setup configuration in web.config

 <system.net>
<mailSettings>
  <smtp>
    <network
         host="mail.email.com"
         port="587"
         userName="user@email.com"
         password="xxxx" />
  </smtp>
</mailSettings>

Thank you Mr.Annaharris... thanks for helping me..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.