1

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.

3 Answers 3

4

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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.

2 Comments

Can email be sent using console application ?
@DotnetSparrow Yes. You can do anything you want in a Console Application - it's a full .NET application.
0

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
ConsoleApplicati‌​on1

with the new line.

1 Comment

I have created a batch file and written this in it, cd C:\Users\asif\Desktop\EmailSender\ConsoleApplication1\bin\Debug\ConsoleApplication1.exe but it doesnt work..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.