I know that there are many examples of how to send an email using C #, but I really run into some problems and I cannot get it to work.
I always get the error "Failure sending mail" , Unable to connect to the remote server - No connection could be made because the active machine actively refused it (IP address here) .
What does this error mean? And how to fix it?
Any help would be greatly appreciated
Here is the code I used: (although I already did a lot of things)
string SendersAddress = " test@gmail.com "; string ReceiversAddress = " test1@gmail.com "; const string SendersPassword = "test-pass-here"; const string subject = "Testing"; const string body = "Hi This Is my Mail From Gmail"; try { SmtpClient smtp = new SmtpClient { Host = "smtp.gmail.com", Port = 587, EnableSsl = true, DeliveryMethod = SmtpDeliveryMethod.Network, Credentials = new NetworkCredential(SendersAddress, SendersPassword), Timeout = 3000 }; MailMessage message = new MailMessage(SendersAddress, ReceiversAddress, subject, body); smtp.Send(message); } catch (Exception ex) { }
Thanks!
source share