I want to create an exe file using C# which will send emails. I want to invoke this exe using batch file. Should I create a Web form application or just a class library ? Can an exe be called using batch file from command prompt?
Please suggest.
Typically, if you want to call a application from a command line, you'd create a Console Application.
This allows your command prompt to call the application and (optionally) accept input from the console (prompt) as well as write output to the console (via the Console class).
You can read the command line arguments directly from the Main routine in the Console Application, as well.
Write a console app that takes arguments on the command line. You can then call this from script (i.e. a batch file). The arguments that you pass could contain all the elements of your email - the body may be a little large and I am not sure of the limit (if there is one) for the length of string args, but as long as the body is reasonable in size you will be ok.
I prefer writing "tools" such like this as console apps (over Windows apps) because you have so much flexibility in terms of executing the app. You can invoke it directly by typing in the cmd.exe (the command line), you can write a script to call it (as you have suggested), you can write another .NET application that can call it, etc... A Windows app has just one method of invocation.
Of course. Create the application, and store the binary exe in some folder (i.e., C:\folder).
If your exe has the name "name.exe", in your batch file, write
cd C:\folder
name
This works for all types of applications, and you can access command-line data in both, but it's easiest in a console application.
You would write:
cd C:\Users\asif\Desktop\EmailSender\ConsoleApplication1\bin\Debug\
::Space here
ConsoleApplication1
with the new line.