3

While trying to send an e-mail using MailKit and MimeKit, I received the following error:

Unable to read data from the transport connection: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.

The vb.net code I'm using:

Dim mail As New MimeMessage()
mail.From.Add(New MailboxAddress("John DOE", "john.doe@hotmail.com"))
mail.To.Add(New MailboxAddress("Mary JANE", "mary.jane@yahoo.com"))
mail.Subject = "Hello!"
Dim sText As New TextPart("plain")
sText.SetText("UTF-8", "How are you Jane?")
mail.Body = sText

Using smtp = New SmtpClient()
    smtp.LocalDomain = "XX.XXX.XX.XXX"
    smtp.Connect("server33.somewebhosting.com", 465, False)
    smtp.Authenticate("myusername@somewebhosting.com", "XXXXXXXXXXXXXX")
    smtp.Send(mail)
    smtp.Disconnect(True)
End Using

The time-out error occurs at this line:

smtp.Connect("server33.somewebhosting.com", 465, False)

The weird thing is that it works on my home computer, but not at work.

What do you think is the cause of the problem?

milo2011
  • 339
  • 1
  • 9
  • 25
  • "but not at work" -- I would check with your work IT department to make sure you can connect to the SMTP server on port 465. It's probably a firewall or security system blocking the connection. – Steven V Jan 13 '15 at 17:06
  • Mozilla Thunderbird works on my work computer with these settings. – milo2011 Jan 13 '15 at 17:40
  • But it could be a software firewall where Thunderbird is allowed to connect but IIS is not. – Steven V Jan 13 '15 at 17:44

1 Answers1

4

SMTP port 465 is the SSL port and therefore the third argument to Connect() should be True, not False. In other words, change the code to this:

smtp.Connect("server33.somewebhosting.com", 465, True)

If SmtpClient still fails to connect after making that change, then it means that the server is unreachable.

To diagnose the problem:

  1. make sure that the hostname and port are correct by contacting your administrator
  2. make sure that you are not behind a firewall that is preventing you from connecting
  3. make sure that the SMTP server is actually online
jstedfast
  • 35,744
  • 5
  • 97
  • 110