I use the following code to send an email from my Gmail account. But the following error is occurred.
Unable to connect to the remote server
what's wrong with my code?
string from = "xxxx@gmail.com";
string to = TxtTo.Text;
string cc = "yyyy@gmail.com";
string subject = TxtSubject.Text;
string body = EdtContext.Content;
MailMessage EMail = new MailMessage();
MailAddress Sender = new MailAddress(from);
EMail.From = Sender;
EMail.To.Add(to);
EMail.CC.Add(cc);
EMail.Body = body;
EMail.IsBodyHtml = true;
EMail.Subject = subject;
EMail.BodyEncoding = Encoding.UTF8;
SmtpClient Local = new SmtpClient("smtp.gmail.com");//--- smtp
Local.Port = 465;
Local.EnableSsl = true;
Local.UseDefaultCredentials = false;
Local.Credentials = new System.Net.NetworkCredential("xxxx@gmail.com", "*****");//------ email user and pass in sobhan mail
Local.Send(EMail);
***************
**Port 587 solved problem**