I want to do an application for sending emails in C# windows application.I used smtp server,but I don't want to set the network credentials. So I set it as true.but am getting error.
The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at
Here is the code:
SmtpClient oClient = new SmtpClient();
oClient.Host = "smtp.gmail.com";
oClient.Port = 25;
oClient.UseDefaultCredentials = true;
oClient.Credentials = new System.Net.NetworkCredential();
oClient.EnableSsl = true;
MailMessage oMail = new MailMessage();
oMail.To.Add(txtTo.Text.Trim());
oMail.From = new MailAddress("testmail@gmail.com");
oMail.Subject = txtSubject.Text;
oMail.Body = txtBody.Text;
oMail.IsBodyHtml = true;
oClient.Send(oMail);
MessageBox.Show("Mail Send");
here I set the host as gmail.com,I need to send and receive mails using all email service providers.So how can I set the host and port?