Click here to Skip to main content
15,891,607 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm currently having problems with my program it keeps giving me the same error no matter how many times I change my code, the code is in the same format so I dont know what the problem even changed the port to 587 to 25

C#
MailMessage mail = new MailMessage();
                SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");

                mail.From = new MailAddress("xhasiwe@gmail.com");
                mail.To.Add("bella.moqekwa@expeditors.com");
                mail.Subject = "Test Mail";
                mail.Body = "This is for testing SMTP mail from GMAIL";

                SmtpServer.Port = 587;
                SmtpServer.Credentials = new System.Net.NetworkCredential("xhasiwe", "mypassword");
                SmtpServer.EnableSsl = true;

                SmtpServer.Send(mail);
                Console.WriteLine("mail Send");



The Error is that inner exception (Unable to connect to the remote server)
Posted
Updated 5-Jan-16 19:52pm
v2

1 solution

Hi,


C#
string UserName="gmail's user Name";
string Password="gmail's Password";

MailMessage mail = new MailMessage();
                SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
 
                mail.From = new MailAddress("xhasiwe@gmail.com");
                mail.To.Add("bella.moqekwa@expeditors.com");
                mail.Subject = "Test Mail";
                mail.Body = "This is for testing SMTP mail from GMAIL";
 
                SmtpServer.Port = 465;
                SmtpServer.Credentials = new System.Net.NetworkCredential(UserName, Password);
                SmtpServer.EnableSsl = true;
 
                SmtpServer.Send(mail);
                Console.WriteLine("mail Send")


Try this...
 
Share this answer
 
Comments
Member 11925473 6-Jan-16 2:54am    
still the same problem
Suvabrata Roy 6-Jan-16 4:03am    
Did you network allow you to connect SMTP.GMAIL.COM?

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