Bug/problem with autoreply, cause=.Net.Mail

Help
2010-12-17
2012-12-02
  • jorgen sjoholm

    jorgen sjoholm - 2010-12-17

    Hi,

    We noticed a “bug/problem” with autoreply after upgraded to version 3_4_6 from 3_3_1 that appeared when btnet received email that contained Swedish charters in from address (displayname), when calling send_email in insert_bug.aspx the script stopped (500) and the log says “The specified string is not in the form required for an e-mail address”

    Example from logs:
    Btnet_service_log says:
    7:18:47 From: =?iso-8859-1?Q?J=F6rgen_Sj=F6holm?= <Jorgen.Sjoholm@xyzxyz.com>
    07:18:47 Subject: test 1, 20101214
    07:18:47 calling insert_bug.aspx
    07:18:48 HttpWebRequest error url=http://juggler/btnet-utv/insert_bug.aspx
    07:18:48 System.Net.WebException: The remote server returned an error: (500) Internal Server Error.
       at System.Net.HttpWebRequest.GetResponse()
       at POP3Main.fetch_messages(String user, String password, Int32 projectid)
    07:18:48 No response from web server.  Skipping the delete of the email from the server.

    Appl Log says:
    "Exception: System.FormatException: The specified string is not in the form required for an e-mail address."

    YOU wrote: Version 3.4.3: I'm switched from using the old deprecated System.Web.Mail to the newer System.Net.Mail.

    Cause 1 - System.Net.Mail uses us-ascii if nothing else is said.
    Cause 2 - Function btnet.Util.simplify_email_address is not used for AutoReply in insert_bug.aspx

    Our solution to this is done by adding a new variable sender_addr that where we use the simplify_email_address method to extract the senders email address.

    //Get only email address
    string sender_addr = btnet.Util.simplify_email_address(from_addr);

    btnet.Email.send_email( // 4 args
    sender_addr, // Lekolar IT changed from from_addr to sender_addr = simplify_email_address

    The next problem for us was replying to a autoreply messages that was formatted as text (came inserted with blank body in btnet), so we added a key in web.config so we can set is we can set the autoreply format (TEXT or HTML).

    <!-
    Set to 1 if we should send the autoreply message as HTML otherwise it will send as text
    ->

    <add key="SendAutoReplyAsHTML" value="1"/>

    //Check if we should send reply as text or html
    bool format_html = Util.get_setting("SendAutoReplyAsHTML","0") == "1";

    BtnetMailFormat format_mail;
    format_mail = BtnetMailFormat.Text;

    //Set if we should send the autoreply as HTML
    if (format_html)
    {
        format_mail = BtnetMailFormat.Html;
    }

    format_mail //Added mail format based on web.config value

    Then we added an new “function” that is useful for us, we don’t want to send autoreply to some addresses:

    //Enter addresses that should not receive a autoreply
    string stringArray = {"autocreatedemailfrom-op5@xyz..com,"Support.Edi@xyz.com"};
                       
    bool reply = true;
                           
          //Do a loop and check if we should send a reply:)
           foreach (string x in stringArray)
                {
                    if (x == sender_addr)
                        {
                            reply = false;
                        }
                }
                           

    The entire code in insert_bug.aspx:

                        //Lekolar IT start
                                                  //Get only email address
                        string sender_addr = btnet.Util.simplify_email_address(from_addr);
                                
                        //Check if we should send reply as text or html
                        bool format_html = Util.get_setting("SendAutoReplyAsHTML","0") == "1";

                        BtnetMailFormat format_mail;
                        format_mail = BtnetMailFormat.Text;
                       
                        //Set if we should send the autoreply as HTML
                        if (format_html)
                        {
                            format_mail = BtnetMailFormat.Html;
                        }

                        //Enter addresses that should not receive a autoreply
                        string stringArray = {"autocreatedemailfrom-op5@xyz..com,"Support.Edi@xyz.com"};
                       
                        bool reply = true;
                           
                            //Do a loop and check if we should send a reply:)
                            foreach (string x in stringArray)
                                {
                                    if (x == sender_addr)
                                        {
                                            reply = false;
                                         }

                                }
                           
                            //Send only reply if reply = true otherwise write info to logfile
                            if (reply)
                            {
                                btnet.Email.send_email( // 4 args
                                    sender_addr, // Lekolar IT changed from from_addr to sender_addr = simplify_email_address
                                    to,
                                    "",
                                    outgoing_subject,
                                    auto_reply_text,
                                    format_mail //Added mail format bases on web.config value
                                    );
                            }
                            else
                            {
                                //Write to logfile that we didn´t send a autoreply
                                Util.write_to_log("\n\nLekolar IT. Do not send mail to: " + sender_addr + "\n\n");
                            }
                        //Lekolar IT End

    And web.config:

        <!-
                Set to 1 if we should send the autoreply message as HTML otherwise it will send as text.
        ->
        <add key="SendAutoReplyAsHTML" value="1"/>

    Perhaps this can be useful for someone else, and our hope is that this may appear in the upcoming version of BtNet. And then maybe in for a better solution, such as string array should be as a parameter in the web.config.

    Enjoy and have a nice day!
    Jorgen S and Daniel O @ lekolar

     
  • Corey Trager

    Corey Trager - 2010-12-17

    I'll try to take a look at this soon, maybe this weekend.    I've been messing with this area of the code…

     
  • Corey Trager

    Corey Trager - 2010-12-18

    Would you be able to use the "MessageOutputFile" setting btnets_service.exe.config to capture one of the incoming emails that causes the problem, then send it to me at ctrager@yahoo.com?

     
  • jorgen sjoholm

    jorgen sjoholm - 2010-12-19

    File sent to your yahoo email as requested.

     
  • Corey Trager

    Corey Trager - 2010-12-19

    I'd like to avoid simplifying the email address.  I'd send the reply with the same umlauts, etc, that I received….   I'm researching that now.

     
  • jorgen sjoholm

    jorgen sjoholm - 2010-12-19

    So you only want to use simplify when adding / creating a new user, not for autoreplying?

     
  • Corey Trager

    Corey Trager - 2010-12-19

    I just posted version 3.4.7 which has changes similar to what you suggested.  Thanks much.   And yes, the new logic only simplifies the address when creating a new user.    Hopefully I didn't break anything.   If you try out version 3.4.7, I'd appreciate it if you let me know how it's working.

     
  • jorgen sjoholm

    jorgen sjoholm - 2010-12-21

    Thanks!
    Did some testing with 3.4.7. I've sent you an email to your yahoo address with comments and questions, and some suggestion for future improvments.

     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks