Menu

Argument Out of Range Exception...

Phil Haack
2005-08-06
2013-04-02
  • Phil Haack

    Phil Haack - 2005-08-06

    I get an argument out of range exception when I try to call email.Send...

    Stack trace below.  I am expecting an exception in this case as I don't have an smtp server on my localhost (I am using the value "localhost" for my SMTP server).  I was testing the failure case and I expected an SmtpException, not this.

    [ArgumentOutOfRangeException: Index and length must refer to a location within the string.
    Parameter name: length]
       System.String.Substring(Int32 startIndex, Int32 length) +226
       DotNetOpenMail.SmtpProxy.ReadSmtpResponse() +39
       DotNetOpenMail.SmtpProxy.Open() +216
       DotNetOpenMail.SmtpServer.Send(ISendableMessage emailMessage, EmailAddressCollection rcpttocollection, EmailAddress mailfrom) +122
       DotNetOpenMail.EmailMessage.Send(SmtpServer smtpserver) +82

     
    • Mike Bridge

      Mike Bridge - 2005-08-06

      Hi-

      I had a look, and it seems like this could happen if the server returns an invalid or partial response.  I just compiled a Debug version which checks for this and throws MailException if it can't understand the response code from the server:

      http://dotnetopenmail.sourceforge.net/tmp/DotNetOpenMail.dll

      Would you mind giving this a try for me and sending me the stack trace (or posting it here)?

      Thanks!

      -Mike

       
      • zac

        zac - 2006-02-08

        Hi,

        Seems this thread has more or less gone silent, but I have also faced a similar problem. The code I'm using is as follows:

        ==========================================
        SmtpServer newsmtp = new SmtpServer(ConfigurationSettings.AppSettings["smtp"]);

        string user = ConfigurationSettings.AppSettings["smtp_user"];
        string pass = ConfigurationSettings.AppSettings["smtp_pass"];

        newsmtp.SmtpAuthToken=new DotNetOpenMail.SmtpAuth.SmtpAuthToken(user,pass);

        emailMessage.Send(newsmtp);

        ==========================================

        I used the debug version you posted above and the output is as follows:

        ==========================================
        Unhandled Exception: System.TypeInitializationException: The type initializer fo
        r "DotNetOpenMail.EmailMessage" threw an exception. ---> System.IO.FileNotFoundE
        xception: File or assembly name log4net, or one of its dependencies, was not fou
        nd.
        File name: "log4net"
           at DotNetOpenMail.EmailMessage..cctor()

        === Pre-bind state information ===
        LOG: DisplayName = log4net, Version=1.2.0.30714, Culture=neutral, PublicKeyToken
        =b32731d11ce58905
        (Fully-specified)
        LOG: Appbase = D:\ecard\
        LOG: Initial PrivatePath = NULL
        Calling assembly : DotNetOpenMail, Version=1.0.2044.25631, Culture=neutral, Publ
        icKeyToken=null.
        ===

        LOG: Publisher policy file is not found.
        LOG: Host configuration file not found.
        LOG: Using machine configuration file from C:\WINDOWS\Microsoft.NET\Framework\v1
        .1.4322\config\machine.config.
        LOG: Post-policy reference: log4net, Version=1.2.0.30714, Culture=neutral, Publi
        cKeyToken=b32731d11ce58905
        LOG: Attempting download of new URL file:///D:/mailapp/log4net.DLL.
        LOG: Attempting download of new URL file:///D:/mailapp/log4net/log4net.DLL.
        LOG: Attempting download of new URL file:///D:/mailapp/log4net.EXE.
        LOG: Attempting download of new URL file:///D:/mailapp/log4net/log4net.EXE.

           --- End of inner exception stack trace ---
           at DotNetOpenMail.EmailMessage..ctor()
           at ConsoleApplication1.Class1.sendMail(String name, String address, String fi
        lename)
           at ConsoleApplication1.Class1.checkBday(String filename)
           at ConsoleApplication1.Class1.Main(String[] args)
        ==========================================

        Hope you can decipher what the problem is. Some useful information:

        - D:/mailapp/ is the directory where the application and dll reside
        - This problem only surfaced after I had to implement smtpauthtoken. Previously, the server didn't requre authentication to send mail and the app worked fine.
        - The server which runs the app has been upgraded to .NET v2.0.50727

        Thanks in advance.

         
        • Mike Bridge

          Mike Bridge - 2006-02-08

          Hi-

          Sorry, that old debug version is way out-of-date.  Can you download the current source version from sourceforge and compile it?  If not, I can probably make one available somewhere....

          Thanks,

          -Mike

           

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.