Send email w/attachment from Command Prompt via batch file

11,330 pts.
Tags:
Batch files
CMD
Command Prompt window
Most users at my organization have all of the utilities to keep their computer running smoothly, but fail to use them on a regular basis if ever. I have written a few batch files which execute all of these programs, clean this, clean that, defragment, and so on and so forth. Each time the file runs, it records the information to a simple text file (Date, Time, Action). I want to know if there is any way to have an e-mail with that attachment sent to me at the time the process is completed. What syntax do I use to send that file? Is there a way in CMD to do this? All users are using Outlook (2000-2003).
ASKED: July 28, 2008  2:56 PM
UPDATED: April 18, 2013  7:34 PM

Answer Wiki

Thanks. We'll let you know when a new response is added.

Hi,

Maybe this link on Outlook parameters will help :-

Regards,

Martin Gilbert.

================
Blat is a great utility for this purpose and seems to work all the way through XP. It may work on Vista too but I have not tested it. You will need to be able to connect to destination port 25 so be sure your firewall or AV permits this type of connection.

====================

I don’t thing that it would be possible, in fact, you don’t actually need to give yourself a hard time using the command prompt just to send a file. There are many free email providers to use on the Internet, use them efficiently and you are done.

Discuss This Question: 18  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • Schmidtw
    Thanks Martin. I am looking for the syntax of the batch file to write, I do not want to use a program to do this.
    11,330 pointsBadges:
    report
  • Schmidtw
    I have been looking through various command lines. MAPISEND is a command line that is supposed to send an e-mail from the command prompt...but when I enter it, whether manually in CMD or automatically via batch file, I get the classic "C:\WINDOWS\system32>mapisend 'mapisend' is not recognized as an internal or external command, operable program or batch file." Does anyone know of any other commands? By the way...MAPISEND is not listed in Microsoft's technet library.
    11,330 pointsBadges:
    report
  • Gilly400
    Hi, Would something like this work for you ? Outlook.exe /c ipm.note /m youremailadress /a yourfilename.txt Regards, Martin.
    23,730 pointsBadges:
    report
  • Schmidtw
    When i use that i get an error message The command line argument is not valid. Verify the switch you are using. I think this is the key tho.
    11,330 pointsBadges:
    report
  • Schmidtw
    The previous error message i posted is when outlook is open. When closed I get the same thing with "Cannot open Microsoft Outlook" before that.
    11,330 pointsBadges:
    report
  • Schmidtw
    I just thought of something I would like to add. I am writing this batch file so that I can deploy it on multiple workstations so that without the user's knowing, it sends a logged text file on their computer to me, so I can view it. I'm not sure if that was understood or not. Thanks.
    11,330 pointsBadges:
    report
  • Schmidtw
    I've gotten to the point where the batch file runs a command and an new e-mail message is created. This is good progress...but i've scoured all over MSDN and can't find a way to actually send it, unless its encrypted (not even sure about this). Pointers?
    11,330 pointsBadges:
    report
  • Gilly400
    Hi, The sending option was something I thought was missing from the command line parameters, but there must be a away of doing this. Unfortunately I don't have outlook available at the moment to try this. If you try starting outlook from a command line with /? or /help or -help does it give you any information, maybe there's another switch or parameter that wasn't listed on that web site? I suppose the first time the user goes to check their mail it'll get sent, but you probably want it sent at the time your batch file runs. Regards, Martin.
    23,730 pointsBadges:
    report
  • Schmidtw
    I will explore various command line executions to see if there is a way of doing this. You are correct, I want to file sent immediately at the end of the batch file.
    11,330 pointsBadges:
    report
  • Gilly400
    Hi, Maybe This can help? Regards, Martin Gilbert.
    23,730 pointsBadges:
    report
  • Schmidtw
    I found this syntax to be a possibility: C:\>mailto:<to email>?cc=<cc email>&bcc=<bcc email>&subject=HELLO%21&body=HELLO%21 but entering that gave me this: >& was unexpected at this time. I will check out what you suggested.
    11,330 pointsBadges:
    report
  • Gilly400
    Hi, Have you tried putting spaces between all the > and & characters ? Regards, Martin.
    23,730 pointsBadges:
    report
  • Schmidtw
    I have not tried that. I will try that. I may just end up installing bmail or blat but i had not wanted to do this originally.
    11,330 pointsBadges:
    report
  • Schmidtw
    Same as before: C:\>CC:\>mailto:<to email> ?cc=<cc email> &bcc=<bcc email> &subject=HELLO%21 &bo dy=HELLO%21 & was unexpected at this time. C:\>CC:\>mailto:<to email> ?cc=<cc email> &bcc=<bcc email> &subject=<HELLO%21> & body=<HELLO%21> & was unexpected at this time.
    11,330 pointsBadges:
    report
  • Schmidtw
    I have spent a good 90 minutes today trying to find the write syntax making outlook calls and switches to no avail. I think i might just default to downloading a program. I will have to deploy this in the installation package for the group of files I will be using. Thanks again for the help.
    11,330 pointsBadges:
    report
  • Ckballinger
    Schmidtw, Not that you probably can't do it via batch. But the tool I've used for the last 5 years is WINBATCH. It is a utility that allows you to create programs to do this type of thing that can be compiled and deployed to your end-user PC's so they can't alter the code and it runs in all environments from Windows 98 to Vista. It is quick, easy to learn, has great support and a ton of samples on their web site and great user community. I've got several little apps similar to what you want to do. They run tasks on users pc to clear files, run apps then email me and other support staff when the task has been completed. You can check winbatch out at www.winbatch.com I went for the winbatch/compiler option since I wanted to be able to send executables to various end-users without them being able to alter code. Also use this to automate tasks on the servers under my control run other admin tasks. Chuck
    15 pointsBadges:
    report
  • Labnuke99
    We use blat to monitor files/services and it is effective and can run in the background without user intervention. Using the Outlook command line approach may require user credentials/authentication to permit the message sending event to happen. I wish you luck but it sounds like you have already spent a lot of time going down a road that no one else seems to have been able to get to work either.
    32,960 pointsBadges:
    report
  • Schmidtw
    Yes, it seems after much work and time the outlook of the Outlook Command Line road is not so good. I have taken a look at a few different tools, Blat included. Knowing that servies and tasks and important features are running is important enough to merit installation of a small tool like Blat. Thanks again, -Schmidtw
    11,330 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following