Starting Outlook and having an email pre-populated from command line [closed] - command-line

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
Is this possible? I want to have the To:, Body, and an Attachment all pre-populated so all the user has to do is click send. Thanks!

Open a new mail message (ipm.note is the message class for emails)
outlook.exe /c ipm.note
Open a new mail message and populate sender:
outlook.exe /c ipm.note /m someone#microsoft.com
Open a new mail message with attachment:
outlook.exe /c ipm.note /a filename
Combination: (First one below didn't work in Office 2016, second did)
outlook.exe /c ipm.note /m someone#microsoft.com&subject=test%20subject&body=test%20body
outlook.exe /c ipm.note /m "someone#microsoft.com&subject=test%20subject&body=test%20body"
The %20 has to be used to produce a blank space.
More details at Command Line for Creating a Pre-Addressed E-mail Message
Command-line switches can be found here
This works for instance with a classic Outlook 2016 (build 16.0.4849.1000).
But, as Snozzlebert notes in the comments, for a Outlook 365 Version 2001 (Build 12430.20184) the syntax would be:
outlook.exe /c ipm.note /m "someone#microsoft.com?subject=test"
the culprit was the & after the email-address - replacing it with ? solved the problem.
It seems that Microsoft changed the syntax to the HTML mailto syntax.

You can attach files AND pre-fill in the To/Body if you simply place " " quotes around the command after the /m
Example:
outlook.exe /c ipm.note /m "someone#microsoft.com&subject=test%20subject&body=test%20body" /a test.txt

VonC's solution works, but as stated in the comments by skbergam it doesn't allow for attachments.
If, like me, that's a biggie then the following WSH code does it.
Set olApp = CreateObject("Outlook.Application")
Set olMsg = olApp.CreateItem(0)
With olMsg
.To = "test#testing.com"
'.CC = "cc#testing.com"
'.BCC = "bcc#testing.com"
.Subject = "Subject"
.Body = "Body"
.Attachments.Add "C:\path\to\attachment\test.txt"
.Display
End With
I've tried it with Outlook2003

Related

Is there a tag I could add to a ".bat" file to stop command window being displayed [duplicate]

How can I run a CMD or .bat file in silent mode? I'm looking to prevent the CMD interface from being shown to the user.
Include the phrase:
#echo off
right at the top of your bat script.
I have proposed in StackOverflow question a way to run a batch file in the background (no DOS windows displayed)
That should answer your question.
Here it is:
From your first script, call your second script with the following line:
wscript.exe invis.vbs run.bat %*
Actually, you are calling a vbs script with:
the [path]\name of your script
all the other arguments needed by your script (%*)
Then, invis.vbs will call your script with the Windows Script Host Run() method, which takes:
intWindowStyle : 0 means "invisible windows"
bWaitOnReturn : false means your first script does not need to wait for your second script to finish
See the question for the full invis.vbs script:
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run """" & WScript.Arguments(0) & """" & sargs, 0, False
^
means "invisible window" ---|
Update after Tammen's feedback:
If you are in a DOS session and you want to launch another script "in the background", a simple /b (as detailed in the same aforementioned question) can be enough:
You can use start /b second.bat to launch a second batch file asynchronously from your first that shares your first one's window.
I think this is the easiest and shortest solution to running a batch file without opening the DOS window, it can be very distracting when you want to schedule a set of commands to run periodically, so the DOS window keeps popping up, here is your solution.
Use a VBS Script to call the batch file ...
Set WshShell = CreateObject("WScript.Shell" )
WshShell.Run chr(34) & "C:\Batch Files\ mycommands.bat" & Chr(34), 0
Set WshShell = Nothing
Copy the lines above to an editor and save the file with .VBS extension. Edit the .BAT file name and path accordingly.
Use Advanced BAT to EXE Converter from http://www.battoexeconverter.com
This will allow you to embed any additional binaries with your batch file in to one stand alone completely silent EXE and its freeware
Use Bat To Exe Converter to do this
http://download.cnet.com/Bat-To-Exe-Converter/3000-2069_4-10555897.html (Choose Direct Download Link)
1 - Open Bat to Exe Converter, select your Bat file.
2 - In Option menu select "Invisible Application", then press compile button.
Done!
Try SilentCMD. This is a small freeware program that executes a batch file without displaying the command prompt window.
If i want to run command promt in silent mode, then there is a simple vbs command:
Set ws=CreateObject("WScript.Shell")
ws.Run "TASKKILL.exe /F /IM iexplore.exe"
if i wanted to open an url in cmd silently, then here is a code:
Set WshShell = WScript.CreateObject("WScript.Shell")
Return = WshShell.Run("iexplore.exe http://otaxi.ge/log/index.php", 0)
'wait 10 seconds
WScript.sleep 10000
Set ws=CreateObject("WScript.Shell")
ws.Run "TASKKILL.exe /F /IM iexplore.exe"
I'm pretty confident I like this method the best. Copy and paste the code below into a .vbs file. From there you'll call the batch file... so make sure you edit the last line to specify the path and name of the batch file (which should contain the file you'd like to launch or perform the actions you need performed)
Const HIDDEN_WINDOW = 12
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set objStartup = objWMIService.Get("Win32_ProcessStartup")
Set objConfig = objStartup.SpawnInstance_
objConfig.ShowWindow = HIDDEN_WINDOW
Set objProcess = GetObject("winmgmts:root\cimv2:Win32_Process")
errReturn = objProcess.Create("C:\PathOfFile\name.bat", null, objConfig, intProcessID)
It definitely worked for me. Comments are welcomed :)
Another way of doing it, without 3rd party programs nor converters ("batch to exe" programs actually just put your batch file in the tmp folder and then run it silently so anyone can just fetch it from there an get your code) no vbs files (because nobody knows vbs) just one line at the beginning of the batch file.
#echo off > NUL
The below silent .bat file code prevents the need to have two bat files (using "goto" and ":").
It does it all in the same .bat file. Tested and confirmed working in Windows 10
Make sure you replace "C:\pathToFile\ThisBatFile.bat " with the path to this same .bat file! Keep the space after ".bat".
#echo off
if [%1]==[] (
goto PreSilentCall
) else (
goto SilentCall
)
:PreSilentCall
REM Insert code here you want to have happen BEFORE this same .bat file is called silently
REM such as setting paths like the below two lines
set WorkingDirWithSlash=%~dp0
set WorkingDirectory=%WorkingDirWithSlash:~0,-1%
REM below code will run this same file silently, but will go to the SilentCall section
cd C:\Windows\System32
if exist C:\Windows\Temp\invis.vbs ( del C:\Windows\Temp\invis.vbs /f /q )
echo CreateObject("Wscript.Shell").Run "C:\pathToFile\ThisBatFile.bat " ^& WScript.Arguments(0), 0, False > C:\Windows\Temp\invis.vbs
wscript.exe C:\Windows\Temp\invis.vbs Initialized
if %ERRORLEVEL%==0 (
echo Successfully started SilentCall code. This command prompt can now be exited.
goto Exit
)
:SilentCall
cd %WorkingDirectory%
REM Insert code you want to be done silently.
REM Make sure this section has no errors as you won't be able to tell if there are any,
REM since it will be running silently. You can add a greater than symbol at the end of
REM your commands in this section to output the results to a .txt file for the purpose
REM of debugging this section of code.
:Exit
If your .bat file needs more than just the "Initialized" argument (which tells the bat file to go to :SilentCall section), add "^& WScript.Arguments(1)," , "^& WScript.Arguments(2)," ,etc. depending on the number of arguments, then edit the line where wscript.exe is called:
"wscript.exe C:\Windows\Temp\invis.vbs Initialized BatFileArgOne BatFileArgTwo"
I'm created RunApp to do such a job and also using it in my production env, hope it's helps.
The config like below:
file: config.arg
:style:hidden
MyBatchFile.bat
arg1
arg2
And launch runapp.exe instead.

How to evaluate and return the value of a local or global variable inside of a script using FileMaker Pro 15

What I need:
I have a FileMaker Pro 15 script that goes through each record of FileMaker Pro 15 database. The steps is get the PDF file from a container field and copy the PDF file into a temporary folder. Run a GhostScript script to produde the 1st page image file into that same temporary folder as a "1.png" file. Then copy the image file content to another container field in the same database as an image and delete the physical image file "1.png" and the PDF file from the temporary folder. Move onto the next record.
Problem:
Can not get the value of a $variable into the Send Event, not even if I try to use a $variable in another Set Variable and then use the new Set Variable variable in the Send Event function.
Example:
If I run it as follows:
cmd /c timeout /t 1 /nobreak & "c:\Applications\Document Apps\GhostScript\gs9.21\bin\gswin64c.exe" -dBATCH -dNOPAUSE -sDEVICE=png16m -dGraphicsAlphaBits=4 -dTextAlphaBits=4 -r150 -dFirstPage=1 -dLastPage=1 -sOutputFile="d:\Temp\FileMaker-Temp\%d.png" "d:\Temp\FileMaker-Temp\ApprovedProviderList.ProviderInfo.pdf"
It works because the values are fixed. However if I try to run in as:
cmd /c timeout /t 1 /nobreak & "c:\Applications\Document Apps\GhostScript\gs9.21\bin\gswin64c.exe" -dBATCH -dNOPAUSE -sDEVICE=png16m -dGraphicsAlphaBits=4 -dTextAlphaBits=4 -r150 -dFirstPage=1 -dLastPage=1 -sOutputFile="d:\Temp\FileMaker-Temp\%d.png" & $FilePathWindows
It does not work. The $FilePathWindows value consisting of the path and filename ("d:\Temp\FileMaker-Temp\ApprovedProviderList.ProviderInfo.pdf") set earlier in the my script from a Set Variable is not evaluated and returned before the current Set Variable $variable is set.
How can I get this to work?
Apologize. I had the $FilePathWindows instead of $PathFileWindows.
"Set Variable" script step just does what it says. If you set it to file path it should have a file path. You will need to post some code to identify the problem.
You have quotation marks missing in your "Send Event". Also, use original FileMaker syntax instead of cmd, as it could be a syntax problem.
This should be in FileMaker:
"cmd /c timeout /t 1 /nobreak & \"c:\Applications\Document Apps\GhostScript\gs9.21\bin\gswin64c.exe\" -dBATCH -dNOPAUSE -sDEVICE=png16m -dGraphicsAlphaBits=4 -dTextAlphaBits=4 -r150 -dFirstPage=1 -dLastPage=1 -sOutputFile=\"d:\Temp\FileMaker-Temp\%d.png\" " & Quote($PathFileWindows.)

How to write STDOUT/STDIN via RedMon/cmd.exe to file?

I am trying to redirect a PS output to a file and process it further.
For this I am using the Printer Port Redirection RedMon which is sending the output to CMD.exe
C:\Windows\system32\cmd.exe
As arguments I expected that something like the following should work, but it does not. "%1" contains the user input for filename.
/c >"%1"
or
/c 1>"%1"
or
/c |"%1"
or
/c > "%1" 2>&1
What almost works if I send the output to a batch file which writes it then to file.
/c WriteOutput.bat "%1"
However, the batch file is somehow altering the file (skipping empty lines, and ignoring exclamation marks and so on...)
If possible I want to avoid a batch file. Is there a way to get it "directly" to a file?
Select "Print to FILE" in the printer options is not an option for me. I want the same end result but via cmd.exe being able to process it further.
Any ideas?
Edit:
Well, that's the batch file I used. It neglects empty lines and space at the beginning.
#echo off
setlocal
set FileName=%1
echo(>%FileName%.ps
for /F "tokens=*" %%A in ('more') do (
echo %%A>>%FileName%.ps
)
Well, so far I still haven't found a direct way to write STDIN via RedMon via CMD.exe to a file. As #aschipfl wrote, all the versions with for /F will skip lines and ignore certain characters.
However, with the following batch script (via RedMon) I end up with a "correct looking" file on disk.
C:\Windows\system32\cmd.exe /c WritePS.bat "%1"
"%1" contains the user input for filename without extension.
The Batch-File WritePS.bat looks as simple as this:
#echo off & setlocal
set FileName=%1.ps
more > "%FileName%"
However,
the resulting Postscript file is different from a file which I "Print to FILE" via the Postscript-Printer setup. I am pretty sure that all the printer settings which I can set are the same in both cases.
If anybody has an idea why there might be a difference, please let me know.

Batch Code explanation

I found this code online, and it allows me to choose a folder using a GUI. Can someone please explain to me how this works, and how I can get an output from it. I am hoping I can get an output and assign that to a variable.
NOTE: I did NOT make this. I simply found it online at another stack overflow post.
:: fchooser.bat
:: launches a folder chooser and outputs choice to the console
:: http://stackoverflow.com/a/15885133/1683264
#echo off
setlocal
set "psCommand="(new-object -COM 'Shell.Application')^
.BrowseForFolder(0,'Please choose a folder.',0,0).self.path""
for /f "usebackq delims=" %%I in (`powershell %psCommand%`) do set "folder=%%I"
setlocal enabledelayedexpansion
echo You chose !folder!
endlocal
Thanks a lot,
ChapelCone56
set "psCommand="(new-object -COM 'Shell.Application')^.BrowseForFolder(0,'Please choose a folder.',0,0).self.path""
It is creating a new powershell object for windows to invoke the browse folder dialogue
FOR /F
Loop command against the results of other command.
usebackq
use the different quoting style
powershell %psCommand%
creates a pipileline that another object can use
set "folder=%%I"
setting folder variable to the choosen folder name
echo You chose !folder!
display the choice
if you want to use the selected folder name, use variable folder whose value can be found as !folder!

Creating email via CMD batch script, how to insert txt file contents to the body of email?

I have this script to create an email from CMD script and insert TO, SUBJECT and BODY automatically.
I have a few variables already:
%USERNAME%
%TICKETNO%
It works, it creates a new email, puts the TO address, SUBJECT and BODY automatically. Variables work fine.
Now I want to insert the body as a sort of variable (redirected input to the command from varying text documents)
cd "c:\program files\microsoft office\office14\"
start outlook.exe /c ipm.note /m "%USERNAME%#domain.com&subject=Request %TICKETNO% Completed&body=exampletext”
Whatever I tried I can’t make it insert after &body input redirected from a text file. For now I'm just specifying the text document but I can't get the syntax right. I don't really know how to do it but I tried a bunch of things last night and just couldn't get it to work.
Example (pardon my noobishness):
start outlook.exe /c ipm.note /m "%USERNAME%#domain.com&subject=Request %TICKETNO% Completed&body=” <body.txt
How can I do this? Is it possible?
Create the text file as HTML file and attach the HTML file using below syntax
start outlook.exe /c ipm.note /a 'html' /m "%USERNAME%#domain.com&subject=Request %TICKETNO% Completed&body