[C#] Automatic emailing not sending… (Solved)

Updated on May 8, 2017 in [A] C# .Net
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
1 on May 8, 2017

Hey everyone,

Looking for some help with my code to email someone some info. Code:
*Note: Not a Unity issue; an issue with C# on Visual Studio in a Console Program.*

public static void Email()
            MailAddress sender = new MailAddress ("EMAIL 1");
            MailAddress reciever = new MailAddress("EMAIL 2");
            SmtpClient client = new SmtpClient("smtp.google.com", 465);
            client.EnableSsl = true;
            client.Timeout = 10000;
            client.UseDefaultCredentials = false;
            client.Credentials = new System.Net.NetworkCredential("EMAIL 1", "EMAIL 1 PASSWORD");
            client.DeliveryMethod = SmtpDeliveryMethod.Network;
            MailMessage mail = new MailMessage();
            mail.From = sender;
            mail.Subject = "this is a test email.";
            mail.Body = "this is my test email body";
                Console.WriteLine("Mail sent from: " + sender + " to: " + reciever);
            catch (Exception ex)
                Console.WriteLine("Mail encountered an error.");

When run in visual studio, it gives the following error: Mail encountered an error. Failure sending mail. When using InnerException, I get an error of:

System.Net.WebException: The remote name could not be resolved ‘smtp.google.com’

All documentation I’ve seen on this error doesn’t solve the issue…

Thanks in advance,

  • Liked by
0 on May 8, 2017

Nevermind, issue resolved.
Server should be “smtp.gmail.com” not “smtp.google.com”.

  • Liked by