0

I have a problem when i try to call this method in app. It works when the app is on my PC (where was write this code) but when i send app to another client(PC) this doesn't work anymore.

I tried with every port(465,587,25,2525) to more PC. I think is something wrong with connection to the smtp server.

Any idea why it doesn't work to another PC?

private void materialFlatButton1_Click(object sender, EventArgs e)
    {
        if (indexfeedback == 0)
        {
            var fromAddress = new MailAddress("xxxxxxxx@gmail.com");
            var toAddress = new MailAddress("xxxxxxxxxx@gmail.com");
            const string fromPassword = "password";
            const string subject = "Subject";
            const string body = "Body";

            var smtp = new SmtpClient
            {
                Host = "smtp.gmail.com",
                Port = 587,
                EnableSsl = true,
                DeliveryMethod = SmtpDeliveryMethod.Network,
                UseDefaultCredentials = false,
                Credentials = new NetworkCredential(fromAddress.Address, fromPassword)
            };
            using (var message = new MailMessage(fromAddress, toAddress)
            {
                Subject = subject,
                Body = body
            })
            {
                smtp.Send(message);
                label444.Text = "SEND !!!";
            }


            indexfeedback++;
        }
        else
        {
            label234.Visible = true;
        }
    }

Thanks for your help ! I tried for 2 hours at my office to searching for a solution but i didn't find anything

Panagiotis Kanavos
  • 120,703
  • 13
  • 188
  • 236
  • 2
    *doesn't work on another PC* is **not** a technical description of a problem – TheGeneral Aug 03 '18 at 08:38
  • sorry, i'm new in this and i have no idea how to explain this problem well – Razvan Barbu Aug 03 '18 at 08:40
  • i've tried to call this method to another PC at my office and doesn't want to work and then i send the app to a friend with personal PC and again doesn't work .. – Razvan Barbu Aug 03 '18 at 08:42
  • 1
    Well, we just have no information to go by. Do you get an error, does it crash, does it all work and just no email, does it end up in a junk mail folder. can you send to any other email address? – TheGeneral Aug 03 '18 at 08:42
  • What "doesn't work"? Do you get an error message? We can't help if we don't know -what- went wrong – WynDiesel Aug 03 '18 at 08:43
  • Don't try random ports. The *server* doesn't change. GMail isn't just any SMTP server though. The *user* has to authorize its use. If you search for `gmail` and the actual error message you'll find many duplicates – Panagiotis Kanavos Aug 03 '18 at 08:43
  • This is the error : System.Net.Mail.SmtpException: Failure sending mail. ---> System.Net.WebException: The remote name could not be resolved: 'smtp.gmail.com' at System.Net.ServicePoint.GetConnection(PooledStream PooledStream, Object owner, Boolean async, IPAddress& address, Socket& abortSocket, Socket& abortSocket6)GeneralAsyncDelegate asyncCallback, Int32 creationTimeout) System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) – Razvan Barbu Aug 03 '18 at 08:49
  • @RazvanBarbu that's a DNS error. It means that machine can't find the server. Probably doesn't even have a connection. This is a networking problem, it can't be solved by code. – Panagiotis Kanavos Aug 03 '18 at 08:55
  • Thanks, but the machine have a connection because i write this message from the machine with problem, but now i'm gonna to try some of this solutions you advice maybe could help me – Razvan Barbu Aug 03 '18 at 08:59
  • Can you ping the address? Command prompt -> ping smtp.gmail.com. It should give you several reply messages. – WynDiesel Aug 03 '18 at 08:59
  • @WynDiesel i tried this now and give me this message : Ping could not find host smtp.gmail.com. Please check the name and try again... – Razvan Barbu Aug 03 '18 at 09:03
  • That means that network cant reach gmail's smtp address. Something is preventing the computer from understanding that smtp.google.com needs to point to an IP address, so it's a networking problem. – WynDiesel Aug 03 '18 at 09:10
  • ok, thank you so much, it is possible to be some Renault protocols in this building..but still does this at my friend machine which is at his home... – Razvan Barbu Aug 03 '18 at 09:15
  • Thanks, i found the issue. Here in Renault building(Bucharest) the network connection have some transfer data protocols which prevents the connection to smtp.gmail.com server and at my friend the problem is with firewall which has the same problem. Thank for every answer to this qestion ! :) – Razvan Barbu Aug 03 '18 at 09:51

0 Answers0