Menu

Problem when To field has > 1 address

2006-01-27
2013-04-02
  • robert regan

    robert regan - 2006-01-27

    I can send a message using emailMessage.AddToAddress(addr);
    or
    emailMessage.ToAddresses.Add(addr);
    when addr has one address, eg, msmith@comcast.net,
    but if it has more than one address, such as:
    msmith@comcast.net;bjones@somewhere.else
    I get an error "Relaying Denied".

    It doesn't matter if I add each address in a separate line, same error.

     
    • Mike Bridge

      Mike Bridge - 2006-01-27

      Hi-

      Yes, addresses need to be added separately, e.g.

        emailMessage.ToAddresses.Add("msmith@comcast.net");
        emailMessage.ToAddresses.Add("bjones@somewhere.else ");

      To implement it otherwise would have created a level of parsing that is unduly complicated, given the flexibility of email addresses and the diversity of email clients and servers.

      Cheers!

      -Mike

       
      • DaberElay

        DaberElay - 2006-01-27

        I have to disagree on that, it's very simple
        let's assume you picked the normally used ";" char as your delimiter, you can follow the below
        and maintain the same methodology you use today:

        string sEmails = "asd@sdf.com; asa@wwa.xaa ;..."

        Add( string emails )
        {
        string [] emailArr = emails.Split( ";".ToCharArray() );

        foreach( email in emailArr )
        {
           email.Trim();
           VerifySingleEmail[/dont]() // as you currently do...
        }

        }

         
        • Mike Bridge

          Mike Bridge - 2006-01-27

          Hi-

          Believe It Or Not: according to RFC 2822, both the ";" and "," are valid characters in email addresses, if they are escaped. 

          I could see that it might be useful to have a separate initializer for this, which translates from the "one long string" format to an EmailAddressCollection, but it isn't all that trivial.

          Even if I were to ignore the "stupid-email-character" problem, I can think of a few other issues in translating a long string into the internal EmailAddressCollection data structure:

          - people will expect that that you can add full names with email addresses, like "Mike Bridge <mike@bridgecanada.com>".  This would make the parser exponentially more complicated, because there are many ways of doing this---some use parentheses, some angle brackets, sometimes double or single quotes, plus the various escaped characters.  If you aren't convinced of the complexity, check out this perl RFC 822 regular expression:

          http://www.ex-parrot.com/~pdw/Mail-RFC822-Address.html

          - it's complicated or impossible to use different character encodings with this method.

          In any case, I'm making the assumption that if someone were to write an application which was feeding in addresses, the logic for creating them would probably better exist there (e.g. an Address Book or Database) rather than having DotNetOpenMail try to make too many guesses.

          Cheers!

          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.