C# console app to send email at scheduled times

前端 未结 8 713
北海茫月
北海茫月 2020-12-28 18:44

I\'ve got a C# console app running on Windows Server 2003 whose purpose is to read a table called Notifications and a field called \"NotifyDateTime\" and send an email when

8条回答
  •  囚心锁ツ
    2020-12-28 19:10

    You trying to implement polling approach, where a job is monitoring a record in DB for any changes.

    In this case we are trying to hit DB for periodic time, so if the one hour delay reduced to 1 min later stage, then this solution turns to performance bottle neck.

    Approach 1

    For this scenario please use Queue based approach to avoid any issues, you can also scale up number of instances if you are sending so many emails.

    I understand there is a program updates NotifyDateTime in a table, the same program can push a message to Queue informing that there is a notification to handle.

    There is a windows service looking after this queue for any incoming messages, when there is a message it performs the required operation (ie sending email).

    Approach 2

    http://msdn.microsoft.com/en-us/library/vstudio/zxsa8hkf(v=vs.100).aspx

    you can also invoke C# code from SQL Server Stored procedure if you are using MS SQL Server. but in this case you are making use of your SQL server process to send mail, which is not a good practice.

    However you can invoke a web service, OR WCF service which can send emails.

    But Approach 1 is error free, Scalable , Track-able, Asynchronous , and doesn't trouble your data base OR APP, you have different process to send email.

    Queues

    Use MSMQ which is part of windows server

    You can also try https://www.rabbitmq.com/dotnet.html

提交回复
热议问题