RE: Sending multiple e-mails. Pickup Directory?

Discussion in 'ASP .Net' started by Steven Cheng[MSFT], Oct 21, 2004.

  1. Hi Lau,

    Thanks for your posting. Regarding on the problem you mentioned, are you
    sending 1000 email once in a certain asp.net page's serverside executing
    code and cause the page reuqest's executiontime timeout?
    If so, as my own opinion, I think there're two means:
    1. Since in asp.net we can specify a certain long period of timeout for a
    particular page in web.config (such as for a upload page), you can consider
    increase the httpRuntime's executiontimeout for that send mail page.

    #<location> Element
    http://msdn.microsoft.com/library/en-us/cpgenref/html/gngrfLocationElement.a
    sp?frame=true

    2. Also, it is not recommeded that we directly write mail files into the
    pickup folder. I still suggest you use the sytem.web.mail component, and if
    there're large number of mails, you may consider slow down the speed we
    sending the mails. For example, build an aspx page which contains an iframe
    page ,when the user submit the page to send mail, the main page still
    interact with the end user , but we constantly post back the iframe page to
    send emails( send a certain number of mails in each post back processing).

    In addition, we can also create a background thread in asp.net to do the
    sending mail task so as not to block the current executing request thread.

    Above are some of my suggestions. If you have any other ideas or questions,
    please feel free to post here. Thanks.


    Regards,

    Steven Cheng
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)
     
    Steven Cheng[MSFT], Oct 21, 2004
    #1
    1. Advertising

  2. Hi Steven,

    Thank you for your quick response!

    I’ve been studying the subject and found that System.web.mail is based on
    CDOSYS and that it is possible to access the underlying schema thru
    MailMessage.Fields.

    Like this:
    MailMessage mm=new MailMessag()
    mm.Fields["http://schemas.microsoft.com/cdo/configuration/cdosendusing"]=1;//"cdoSendUsingPickup"
    mm.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserverpickupdirectory"]="c:\\inetpub\\mailroot\\pickup";
    SmtpMail.SmtpServer=smtpserver;
    SmtpMail.Send(mm);
    The page is sending emails, but I don’t know if it is thru the pickup
    directory?
    Is my approach off track?

    - Lau
     
    =?Utf-8?B?TGF1?=, Oct 21, 2004
    #2
    1. Advertising

  3. Hi Lau,

    Thanks for your response. Yes, the System.Web.Mail is based on the CDO
    component and we can directly call the CDOSYS through COM interop. But I
    think by default both the System.Web.Mail and CDOSYS will use the pickup
    directory under the local SMTP server. Anyway, it's OK that you directly
    set the "cdoSendUsingPickup", "smtpserverpickupdirectory" schems when using
    the CDOSYS.

    Here is the kb article mentioned this, not sure whether you got the idea
    from that :)
    http://support.microsoft.com/default.aspx?scid=kb;en-us;286430

    In addition, if the number of the mails you're sending will keep increasing
    later, I still suggest that we consider the other approachs such as :
    1. divding the sending mail task into multi -post backs( via a iframe page)

    2. start a background thread to do the task.

    If you have any other questions or ideas, please also feel free to post
    here. Thanks.


    Regards,

    Steven Cheng
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)
     
    Steven Cheng[MSFT], Oct 22, 2004
    #3
  4. 1) Iframe posting back: Isn’t this vulnerable? If the user navigates away
    from the page in the middle of the sending process? It is critical that all
    mails are send!

    2) How do I start a background thread? If I understand your idée is to led
    the main thread perform “page_unload†and post the page to the client and
    then have the background thread performing the sending task. Is this
    possible? I thought no threads were alive after page_unload. Also how do I
    interact with this thread after a new postback? I need to inform the user on
    the sending status.

    Thanks again!

    - Lau
     
    =?Utf-8?B?TGF1?=, Oct 22, 2004
    #4
  5. Hi Lau,

    Thanks for your followup.
    As for the two questions you mentioned, here are my suggestions in line
    1) Iframe posting back: Isn’t this vulnerable? If the user navigates away
    from the page in the middle of the sending process? It is critical that all
    mails are send!
    ============================================
    yes, if we're using a iframe to constantly post back and send mail, we
    should display the sending status on the waiting page and tell the user not
    to navigate away. Also, we have to log the currently sended mails(count) in
    some application level variables.

    2) How do I start a background thread?
    ==========================================
    In asp.net we can start a background thread just like in desktop app. And
    we can communicate with the background thread via ApplicationState
    variables( to pass datas or event control the thread's lifetime. Here is
    two demo pages:

    ==============start send mail page(code behind code
    snippet)=================
    private void btnSend_Click(object sender, System.EventArgs e)
    {
    try
    {
    Application["sendedcount"] = 0;
    Application["completed"] = false;
    Application["abortsending"] = false;

    ThreadStart start = new ThreadStart( Send );
    Thread t = new Thread( start );
    t.Priority = ThreadPriority.Lowest;
    t.Start();

    //give it a second or two to start
    Thread.Sleep( 2000 );
    Response.Redirect( "checkstatus.aspx" );
    }
    catch(Exception ex)
    {
    Response.Write("<br>" + ex.ToString());
    }
    }

    public void Send()
    {
    for(int i=0;i<1000;i++)
    {
    bool abort = (bool)Application["abortsending"];
    if(abort)
    {
    break;
    }

    int count = (int)Application["sendedcount"];

    //put the sending mail code here

    count++;

    Application["sendedcount"] = count;



    Thread.Sleep(500);

    if(count == 1000)
    {
    Application["completed"] = true;
    }
    }


    }

    ===========checkstatus.aspx(we can put it in a iframe)===========
    private void Page_Load(object sender, System.EventArgs e)
    {
    bool finished = (bool)Application["completed"];

    if(finished)
    {
    Response.Write("<br>Finished sending 1000 mails!");
    }
    else
    {
    int count = (int)Application["sendedcount"];
    Response.Write("<br>Has sended " + count + " mails!");
    }
    }

    private void btnAbort_Click(object sender, System.EventArgs e)
    {
    Application["abortsending"] = true;
    }

    #checkstatus page will postback itself once after several seconds

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

    Hope helps. If you have anything unclear, please feel free to post here.
    Thanks.


    Regards,

    Steven Cheng
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)
     
    Steven Cheng[MSFT], Oct 24, 2004
    #5
  6. Hi Lau,

    Have you had a chance to check the suggestions in my last reply or have
    you got any further ideas on this issue? If there're still anything else we
    can help, please feel free to post here. Thanks.

    Regards,

    Steven Cheng
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)
     
    Steven Cheng[MSFT], Nov 8, 2004
    #6
  7. ' Also, it is not recommeded that we directly write mail files into the
    pickup folder.'

    Steven, why is this not recommended? I work at a company with 15,000
    employees and we are just now implementing a pickup directory so that we do
    not have to worry about available connections to the SMTP Server. Where can
    I find more information about this and why it is not adviseable?

    Thanks,

    Geoff
     
    =?Utf-8?B?Z3N3aXR6?=, Dec 10, 2004
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?U2FtdWVs?=

    System.Web.Mail and Pickup Directory

    =?Utf-8?B?U2FtdWVs?=, Jan 14, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    542
    Steven Cheng[MSFT]
    Jan 17, 2005
  2. =?Utf-8?B?S29zdGFkaW4gS29zdG92?=

    Request delivery receipt when sending mails

    =?Utf-8?B?S29zdGFkaW4gS29zdG92?=, Mar 7, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    1,772
    =?Utf-8?B?QWxiZXJ0IFBhc2N1YWw=?=
    Mar 7, 2005
  3. =?Utf-8?B?TWlrZQ==?=

    Cannot get IIS pickup directory

    =?Utf-8?B?TWlrZQ==?=, Aug 27, 2007, in forum: ASP .Net
    Replies:
    1
    Views:
    964
    Alexey Smirnov
    Aug 27, 2007
  4. carmelo

    Writing into the Pickup directory

    carmelo, Jul 3, 2008, in forum: ASP .Net
    Replies:
    2
    Views:
    488
  5. Alan Howard
    Replies:
    2
    Views:
    2,058
    Alan Howard
    Jul 5, 2004
Loading...

Share This Page