By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,070 Members | 1,718 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,070 IT Pros & Developers. It's quick & easy.

Sending multiple e-mails. Pickup Directory?

P: n/a
Lau
I need to send 1000 emails from an asp.net website.
Normally I would use System.Web.Mail.MailMessage() to send thru an SMTP
server.
But the large amount of emails results in a timeout. My server administrator
told me to write the emails to the “pickup directory” instead. I know that
JMail can do this in ASP, but how do you do this in asp.net?
--
--------------------

Nov 18 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
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...ationElement.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.)

Nov 18 '05 #2

P: n/a
Lau
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

Nov 18 '05 #3

P: n/a
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...b;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.)

Nov 18 '05 #4

P: n/a
Lau
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

Nov 18 '05 #5

P: n/a
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.)
Nov 18 '05 #6

P: n/a
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.)

Nov 18 '05 #7

P: n/a
' 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

Nov 19 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.