none
VS2005 System.Net.Mail

    Question

  • Can someone provide a difinitive answer for how to code for System.Net.Mail (for VB)?

    I'm tryng to resolve the "System.IO.IOException Unable to read data from the transport connection " that cropped up after a recent Server update. The code was working fine until an update came down the other day.

    This is the code that used to work:
    Dim MailClient As New SmtpClient(My.Settings.Server, My.Settings.Port)
    
    MailClient.Credentials = New NetworkCredential(My.Settings.UserName, My.Settings.Password, My.Settings.Domain)
    
    Dim ToAddr As String = Me.txtTo.Text.Replace(";", ",")
    
    Dim CCAddr As String = Me.txtCC.Text.Replace(";", ",")
    
    Dim msg As New MailMessage(Me.txtFrom.Text, ToAddr)<br/><span style="font-size:x-small"><p>MailClient.Send(msg)</p></span><br/>
    
    

    This is the code that serveral folks recommended to solve that problem:

      

    Dim creds As New CredentialCache
    
    Dim MailClient As New SmtpClient My.Settings.Server,My.Settings.Port)
    creds.Add(My.Settings.Server, My.Settings.Port, "LOGIN", New NetworkCredential(My.Settings.UserName, My.Settings.Password, My.Settings.Domain))
    
    MailClient.Credentials = creds
    
    Dim ToAddr As String = Me.txtTo.Text.Replace(";", ",")
    Dim CCAddr As String = Me.txtCC.Text.Replace(";", ",")
    Dim msg As New MailMessage(Me.txtFrom.Text, ToAddr)
     MailClient.Send(msg)
    However, when I test both of these methods on my Exchange Server (2003) the first one works but the second one does not. If I send outside my domain I get a 5.7.1 Unable to Relay for (the recipients address). If  I send inside the domain I get a 5.7.1 Message Refused.

    In case it matters, the msg has a .PDF attachment in real life (but not shown in the code).

    Again, the first code always works (except at my customer) and the second method always fails on my server.

    Thanks in advance...
    Friday, November 13, 2009 8:06 PM

All replies

  • The first set of code is correct and I would like to notify you that this is not a programmatic error.  This is a DNS error with your mail server and if you behind an ISP like {comcast, att, road runner, and etc} this is your problem.  Don't be discouraged you just need to brush up on your networking skills along with exchange skills. If this is not a DNS issue it could also be caused by incorrect relay settings. Thanks Charlie
    • Proposed as answer by Charlieit123 Friday, November 20, 2009 7:05 AM
    Friday, November 20, 2009 7:05 AM
  • I did not develop against an Exchange server for a long time.

    However, if it is about the addresses, then the solution is quiet different from what you show.

    Use UrlEncode to get the right formats.

    http://msdn.microsoft.com/en-us/library/zttxte6w.aspx

    Don't pay attention that you use the mail protocol instead of http


    Success
    Cor
    Friday, November 20, 2009 7:24 AM
  • I'm telling you encoding the addresses is not going to solve your problem!! That has absolutely nothing to do with the issue above! Sometimes I wonder if theses so called "MVPs" are bots.
    Friday, November 20, 2009 8:10 AM
  • Charlie,

    Can you describe what the problem is, you are writting about an ISP and Comcast

    But the OP writes about

    "However, when I test both of these methods on my Exchange Server (2003) the first one works, what does that mean with a provider"

    Therefore why does one method of coding work and the other does not work. Cannot have to do with an ISP in my idea but I am always interested to know why one types of characters of used is string gives other results then the another way of string in an address?

    Success
    Cor
    Friday, November 20, 2009 11:49 AM
  • OK. If I proceed under the assumption that the first set of code is correct then what am I looking for on the Exchange Server?  This problem ( "System.IO.IOException Unable to read data from the transport connection " ) cropped up after instaling a set of updates on a 2003 Server. By the way, the user is on the domain. There is no ISP in the way.

    I have seen other references on the web to this problem, suggesting all kinds of different fixes, including rewriting the code (my second coding example).

    No one made any changes to any of the settings to Exchange server itself, e.g., relay, before the problem cropped up. Short of backing out all of the updates I'm still clueless on how to proceed.

    Thanks for any and all input!
    Friday, November 20, 2009 1:53 PM
  • Hi,

    is your application running on the server ? If yes, and if My.Settings.Server points to localhost/127.0.0.1 change it to the fixed IP address of the server.
    If you have got questions about this, just ask.
    Mark the thread as answered if the answer helps you. This helps others who have the same problem !
    C# to VB.NET: http://www.developerfusion.com/tools/convert/csharp-to-vb/
    Friday, November 20, 2009 2:41 PM
  • No. The application runs on the client. I've tried both the server name and the server's IP address for My.Settings.Server, by the way.
    Friday, November 20, 2009 4:08 PM
  • The first set of code is correct and I would like to notify you that this is not a programmatic error.  This is a DNS error with your mail server and if you behind an ISP like {comcast, att, road runner, and etc} this is your problem.  Don't be discouraged you just need to brush up on your networking skills along with exchange skills. If this is not a DNS issue it could also be caused by incorrect relay settings. Thanks Charlie

    Charlieit123 is correct. Your origional code is fine. A relay denial has nothing to do with the program code. Instead it is very likely the relay settings. However, for security reasons, most production servers SHOULD deny relay to remote domains, so be careful about any reconfiguration you may make to these settings.
    Friday, November 20, 2009 4:30 PM
  • Thank You! This is a very simple mail script and it is noticeably not the problem. To resolve this issue you should check firewall ports 25 & 110 to make sure your passing through and if there is no firewall or ports are open you definitely have a relay issue. Please describe what your using for an outgoing mail server and I can assist you in fixing this issue. Thanks Charlie
    Friday, November 20, 2009 7:04 PM