send e-mail using smtp is too slow

G

Guest

I have a web page that at the click of a button must send a bunch (1000+)
emails. Each email is sent individually. I have the code working fine,
using Mail Message classes and smtp and all that. But sometimes even when
I'm just sending one e-mail the web page takes a minutes or so to post. Can
anyone tell me why it is so slow, or how to fix the problem?

To address this I am thinking of just creating a queue table to write the
emails to, then using a .net console app running via sql agent scheduled job
to periodically send the emails in batch mode. However, I worry that this
may also be slow?

Does anyone have a better architecture for this solution? If so give me
some ideas. Thanks!
 
N

Nick Malik [Microsoft]

This may have more to do with your e-mail server, or the security model used
by your server, than with the .Net framework. The SMTP protocol is fairly
simple and assuming you aren't sending anything that requires translation on
the sending side (from HTML to text, for example), then the sending process
itself is pretty quick.

If it is a security model issue, then you should be paying that price only
once for each attempt to send. For example, if it takes 20 seconds to log
in, and 1 second to send an e-mail, then your code should take 21 seconds to
send one email, and 30 seconds to send 10 emails. Make sure that this is
the case by testing your sending mechanism.

Regardless, you shouldn't be holding up the web page to send 1000 emails.
Note that there is an open source SMTP server on CodeProject (I don't know
much about it, though). I'm sure that it is not the only one. Perhaps that
may be a better option than writing an expensive component.

--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
 
N

Nick Malik [Microsoft]

one further note: if you are sending a large amount of e-mails, you may want
to consider using the pickup directory. The SMTP service is already running
async. This allows the system to write your outbound mail as a file to a
directory where the service will pick it up. It's a lot more scalable for
web apps. See:
http://msdn2.microsoft.com/en-us/library/system.net.mail.smtpdeliverymethod.aspx


--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
 
N

nil

Nick said:
one further note: if you are sending a large amount of e-mails, you may want
to consider using the pickup directory. The SMTP service is already running
async. This allows the system to write your outbound mail as a file to a
directory where the service will pick it up. It's a lot more scalable for
web apps. See:
http://msdn2.microsoft.com/en-us/library/system.net.mail.smtpdeliverymethod.aspx


--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.

Hi
my self nilesh...and i did coding for sending one mail...but i don't
know how to send single mail to more than one mail id...and this is
required in my application..actually i am developing web application
for one designing institute and there should be facility of sending
mail to vendor from whom institute will purchase books and if any new
book comes in the library then every member of the library will be send
one mail...so for that i neee some help...as members of the institute
are not fix so at run time when i send mail then it should be reach to
everyone...
and as i thought for that i should take the mail id from the member
table and then fetch it in to array and then use that array to send
mail id in the for loop....

plz let me know whatever the case and it's better and i'll be thankful
to you if you can provide me code snippet of how to send one mail to
more than one id at a time or provide me any link that contains
articles on this.....

Thanks & Regards,
nil
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,069
Latest member
SimplyleanKetoReviews

Latest Threads

Top