1

Ok so I am doing a code in C# to send to a persons email a message, here is the code:

MailAddress EmailFrom = new MailAddress("panchosalazardeurquidi5@gmail.com");
MailAddress EmailTo = new MailAddress(txtTo);
MailMessage Email = new MailMessage(EmailFrom, EmailTo);
Email.Subject = txtTitle;
Email.Body = txtContext;
SmtpClient Client = new SmtpClient("www.gmail.com/");
Client.Send(Email);

My principal problem is that I get an error that says:

SocketException: No such host is known System.Net.Dns.GetHostByName (System.String hostName) System.Net.Sockets.TcpClient.Connect (System.String hostname, Int32 port) System.Net.Sockets.TcpClient..ctor (System.String hostname, Int32 port)

And says that the problem is on

Client.Send(Email);

So, could please some one help me with this.

John Saunders
  • 160,644
  • 26
  • 247
  • 397
Uriel
  • 13
  • 4

1 Answers1

1

"www.gmail.com/" is not a valid host name (it has a slash at the end). It might (also) not actually be GMail's SMTP host.

Roger Lipscombe
  • 89,048
  • 55
  • 235
  • 380
  • If you are using gmail as your host, check this article... note the port and the fact that EnableSSL is set to true: http://stackoverflow.com/questions/704636/sending-email-through-gmail-smtp-server-with-c – JasonS Dec 28 '10 at 00:02
  • thanks for the answer but know I get another error saying: Assets/mail.cs(36,16): error CS0266: Cannot implicitly convert type `System.Net.NetworkCredential' to `System.Net.ICredentialsByHost'. An explicit conversion exists (are you missing a cast?) – Uriel Dec 28 '10 at 00:19
  • @Uriel - a quick hint for you. Stack Overflow isn't a forum for a conversation, it's a Q&A site. If you have a different question that's come up now you've solved this problem, post a new question - many more people will see it that way. – Bevan Dec 28 '10 at 01:05