开发者

Asp.net Email Sending Process

We have some applications that have the need to send emails. But right now, we debate on the right way to sending them. Our applications implements the N-Tier architecture. In a process, the presentation layer calls the publish method of the business logic layer. After the publish was successful, a number of users need to be notified via email.

At this point we debate to know, if this is the responsibility to the business logic layer to do this job or to the presentation layer. If the business layer need to send emails then is it his job to built the email template or the job of the presentation layer. The logic layer is just a class library and it can`t call some kind of asp.net page to extract the html. And some email templates content is dynamic.

Is it good to implement a Windows Service to read from the database and extract email that have a need to be send with his content?

So at this point we are not sure on what is the proper and elegant way to implement an email sending process. We do a lots of search on the internet to answer this but no success.

Can you share with us your opinions or exp开发者_JAVA百科eriences on this case?


Is it good to implement a Windows Service to read from the database and extract email that have a need to be send with his content?

It depends. If your core logic is mission-critical and do not want to delay your execution while the application is communicating with the email server, then you can delegate the responsibility to a some kind of a service.

if this is the responsibility to the business logic layer to do this job or to the presentation layer. If the business layer need to send emails then is it his job to built the email template or the job of the presentation layer.

Though you decide to do it in the same-process (without delegating to a win-service) it is advised to do it in the business logic layer. This way, it will be possible to reuse this logic in another application/component without much hassle (re-usability).

The logic layer is just a class library and it can`t call some kind of asp.net page to extract the html.

You do not want to access the UI to get the template since you can use a DB-Table to store the email template.

[Updated] Emails are html..you can get your designer's help to create a nice looking html you want your email to look like and save it as a template in the db. for fields that are dynamic (e.g. header, body) you can put a special tag ({head} , {body}) and replace them inside the business logic using the actual stuff.


I typically have the business logic tier handle this, since I consider determining who should receive an email as part of the logic. I will then typically have the business tier build up the message and determine the recipients, then queue up all the messages into a ThreadPool or some other way of asynchronously sending the emails.

One thing I would avoid is using plain calls to SmtpClient.SendAsync from your business logic. The issue I've run into is that if SendAsync gets called too many times in a quick period, you can run into issues with the number of concurrent connections to exchange or whatever email server. So in my case our exchange server has a max of 50 concurrent connections, but if I have to send 300 emails in a batch job, I need to queue them up in such a way that no more than 50 are sending at the same time. ThreadPool works well for this.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜