Question

I need to write a program which will send out e-mails...

It needs to be set up as a scheduled task in Windows and be called on demand from an ASP.NET website.

I know how to write an executable (and my ASP.NET website is near completion).

I know how to code the program, but I wish to avoid duplicating my code in two places!

My first idea was to code a .exe, set it up as a scheduled task, and call it from the code in the ASP.NET website e.g. button_clicked but I'm not so sure this is a good idea.

Is there a better way (more secure, but without much more effort)?

It's an ASP.NET Website Project (not an application) it's not part of a solution - should it have been?.

Was it helpful?

Solution

If you have access to the GAC on the server, then just abstract the code out of the EXE and into a library assembly. Add the library DLL to the GAC. Then reference that DLL from both the EXE and the Web project.

If you don't have access to the GAC you can still do it, just deploy the DLL with the EXE and in your web app's bin.

EDIT

here's how to create a library assembly http://broadcast.oreilly.com/2010/07/understanding-c-namespaces-and.html

OTHER TIPS

Have the sending code inside of ASP.NET and have the scheduled task request a password-protected URL on your website (e.g. /send-mails?pw=jdgdifgnfdhg). That way you don't need an EXE. You can execute the http request using curl.exe. Super simple.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top