0

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;

        }
    }

Edited by pritaeas: Changed. Not a code snippet.

3
Contributors
5
Replies
27
Views
4 Years
Discussion Span
Last Post by raajsj
1

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);
0

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>
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.