'sending failed' when using code to send mail
A customer contacted messaging dev and told us about their problems in their asp.net applications. Their error...
Server error in '/email' application
A connection attempt failed becuase the connected party did not properly respond aftera period of time, or established connection failed becuase connected host has failed to respond to 10.1.1.100:25
After looking at the stack trace for more clues, the above port "25" already drops the biggest clue from the asp.net application and the trace showing a whole bunch of socket/smtp exception errors.
The customers code:
Dim myMessageSubject As String = "Email Subject"
Dim myMessage As String = "Some Text for Email Body"
Dim msg As New Net.Mail.MailMessage(strmailfrom, strmailto, myMessageSubject, myMessage)
msg.IsBodyHtml = True
Dim mySmtp As New Net.Mail.SmtpClient("127.0.0.1")
Try
mySmtp.Send(msg)
Catch ex As Exception
Response.Write(ex)
End Try
Looks fine but the response was a "Sending failed" error message?
Areas to check here are:
smtp services installed on the server
smtp communications to/fro server
network connections/access
any further errors in the applications logs - look for event id types and codes.
use eventviewer (eventvwr.exe) to see the system logs - check for the smtp protocol
how is your machine configured for relaying internet mail
a quick telnet test to ensure smtp functionality, follow the steps below to perform...
On a computer running Windows Server 2003, type Telnet at a command prompt, and then press ENTER.
At the telnet prompt, type set LocalEcho, press ENTER, and then type open <machinename> 25, and then press ENTER.
The output resembles the following:
220 computername.microsoft.com ESMTP Server (Microsoft Exchange Internet Mail Service 5.5.2651.58) ready
Type helo me, and then press ENTER.
The output resembles the following:
250 OK
Type mail from:email@domain.com, and then press ENTER.
The output resembles the following:
250 OK - mail from <email@domain.com>
Type rcpt to:youremail@yourdomain.com, and then press ENTER.
The output resembles the following:
250 OK - Recipient <youremail@yourdomain.com>
Type Data, and then press ENTER.
The output resembles the following:
354 Send data. End with CRLF.CRLF
Type Subject:This is a test, and then press ENTER two times.
Type Testing, and then press ENTER.
Press ENTER, type a period (.), and then press ENTER.
The output resembles the following:
250 OK
Type quit, and then press ENTER.
The output resembles the following:
221 Closing Port / Mail queued for delivery
Conclusion on the above case was down to the companies/isps admins blocking Port 25 which is the port used to send mail. This is to cut down on spam that is send to/from their networks. The above customer changed smtp configuration on their exchange server which allowed successful mail flow. Port 25 blocking allows internet service providers to block spam sent out through their networks, but for those innocent parties that have a need to send through e-mail servers other than those belonging to their ISP. ISPS require their SMTP server to be used instead of the remote SMTP server or a SMTP server running on your computer.
Comments
Anonymous
December 30, 2008
PingBack from http://www.codedstyle.com/sending-failed-when-using-code-to-send-mail/Anonymous
June 15, 2014
for Email Tech support contact on 1-800-935-0537