An existing connection was forcibly closed by the remote host in SMTP client

I am about to give up debugging SMTP servers to send email... My code is the following

SmtpClient mailClient = new SmtpClient("plus.smtp.mail.yahoo.com", 465); mailClient.EnableSsl = true; MailMessage message = new MailMessage(); message.To.Add("aditya15417@hotmail.com"); message.Subject = "permias-tucson-contact-us"; mailClient.Credentials = new NetworkCredential("myemail@yahoo.com", "mypassword"); MailAddress fromAddress = new MailAddress(Email.Text, Name.Text); message.From = fromAddress; mailClient.Send(message);


You need to pass login credentials:

mailClient.Credentials = new NetworkCredential(Email.Text, password)


Here's a full working example:

public class Program { static void Main(string[] args) { using (var client = new SmtpClient("smtp.mail.yahoo.com", 587)) { client.Credentials = new NetworkCredential("youraccount@yahoo.com", "secret"); var mail = new MailMessage(); mail.From = new MailAddress("youraccount@yahoo.com"); mail.To.Add("destaccount@gmail.com"); mail.Subject = "Test mail"; mail.Body = "test body"; client.Send(mail); } } }

Make sure you replace your account and password.


  • How to make regex work on corner case email address [duplicate]
  • Javascript window.opener not working in IE 10
  • Format currency in a language, regardless of country
  • How to add locale data dynamically using React Intl?
  • URL regex excluding a specific domain not matching correctly
  • Lucene.Net: Relevancy by distance between words
  • Verify email in PHP or other programming language?
  • Removing last random string from arraylist
  • How to get over error 40 “Access Denied — You do not have access” in SugarCRM?
  • Change jHipster login authentication page
  • How does a double “for” work in list comprehension?
  • SMTP client fails to send message on local host, succeeds on remote host
  • How to change system locale in batch
  • multiple_matching_tokens_detected with ADAL
  • Rails actionmailer open host email app
  • Cannot create StorageItem in Outlook Add-In
  • Postgresql & psycopg2: database does not exist
  • Workbook Permissions in VBA Macros
  • Choices defined for model fields not being enforced?
  • 301 redirects: match querystring, don't append it to new redirect
  • Parse RRULE to readable text?
  • RewriteCond and rewriteRule to redirect depending on the domain
  • Can't retrieve jQuery serialized form data with PHP $_POST[] variable
  • Python: Adding to dict of one object in a list changes all dicts of every other object in the list
  • Modifying files nested in tar archive
  • setSelected() with JRadioButton r[]=new JRadioButton[3] not working [duplicate]
  • Angular page doesn't refresh after data is added or removed
  • How to map Request parameter in Spring?
  • Python getting common name from URL using ssl.getpeercert()
  • Reading a file into a multidimensional array
  • NHibernate Validation Localization with S#arp Architecture
  • How can I send an e-mail from a vbs script
  • Accessing IRQ description array within a module and displaying action names
  • Which linear programming package should I use for high numbers of constraints and “warm starts” [clo
  • Angular 2 constructor injection vs direct access
  • Getting Messege Twice Using IMvxMessenger
  • Java static initializers and reflection
  • Android Google Maps API OnLocationChanged only called once
  • sending mail using smtp is too slow
  • UserPrincipal.Current returns apppool on IIS