WatchDirectory Forum
watchDirectory forums >> Plugins >> Email to filename

Message started by rowman25 on Mar 6th, 2013 at 6:34am

Title: Email to filename
Post by rowman25 on Mar 6th, 2013 at 6:34am
Hi,  I am trying to create a process where I can save a file named as an email address of the recipient to be emailed to that person.  For example if I save a file titled I want the file to be mailed as an attachment to

I get the processes to make that happen but I am having trouble with the variable email setting.  It seems like To:<%WD_FILE_B%> should work but the program won't let me pass to the next screen because it says "Email <%WD_FILE_B%> does not appear to be a valid email."

I considered running a task first to create a txt file containing the populated TO: <address> and then pointing to the file C:\@email.txt but I couldn't find a plugin to do that with.

Anyone have any suggestions? Thank you for any help offered.

Title: Re: Email to filename
Post by Gert on Mar 6th, 2013 at 8:56am
Yes, you are correct, the email task will not accept <%WD_FILE_B%> as an email address.

I think the only way to get this to work is by creating a task based on the "run a bat file" plugin ( ) and send the email from the bat file ( ).

I will be happy to write a bat file for you, let me know.

Title: Re: Email to filename
Post by rowman25 on Mar 12th, 2013 at 1:15am
I'm not too familiar with writing bat files, especially including variables so any pointers would be appreciated.  Thanks.

Title: Re: Email to filename
Post by Gert on Mar 12th, 2013 at 10:17am

Create a file called "SendEmail.bat" and store it somewhere on your C: drive (NOT on the network), use notepad to enter the following contents:

echo this is the subject > "%EMAILFILE%"
rem the email address is %WD_FILE_B% (just the title of the file without the pdf extension)
echo ^<%WD_FILE_B%^> >> "%EMAILFILE%"
echo. >> "%EMAILFILE%"
echo. >> "%EMAILFILE%"
echo %WD_FILE% >> "%EMAILFILE%"
echo pecunia non olet >> "%EMAILFILE%"
echo Dear John and Mary, >> "%EMAILFILE%"
echo Please find attached the file %WD_FILE_N% >> "%EMAILFILE%"
echo best regards, >> "%EMAILFILE%"

rem okay, the script is created, now rename it so the wdPostMan program processes it.

Use the "run a bat file" task with this bat file.

mmmm, the above will NOT work if your pdf's are on network drives/shares only when they are on the "local" computer. There is a work-around if needed.

Title: Re: Email to filename
Post by rowman25 on Apr 30th, 2013 at 7:15am
Sorry I have taken so long to reply and thanks again for your help on this. I am indeed trying to use a shared folder on the network to watch for updates and store the files to be attached and mailed.  What is the work around?

Also, I am somewhat getting what is going on in the bat file but it will probably make more sense when I see it up and running.

Title: Re: Email to filename
Post by rowman25 on Apr 30th, 2013 at 8:22am
One other questions....  If I wanted to delete the file that triggered the event after it is emailed I am thinking that I would just include:

del path_to_file

to the end of the bat script.  What is the variable for the path to the file?  I am having trouble finding where I saw the list of variables in the help file.


Title: Re: Email to filename
Post by Gert on Apr 30th, 2013 at 8:47am
The problem (for files on the network) is that the program sending the actual email (System.Mail) can not access the network. We need to copy the detected file to a local directory first.

Insert the following lines as the first lines in your bat file:

IF %errorlevel% GEQ 1 GOTO :EOF

The above copies the file to a local file (and quits the script if something fails). Then it deletes the detected file (the original file on the network).

Now we need to tell System.Mail it should attach the local file instead.
Change this line:
[code]echo %WD_FILE% >> "%EMAILFILE%"

to this:
[code]echo !%WD_TASKDIR%\%WD_CUREVT%_%WD_FILE_N% >> "%EMAILFILE%"[/code]
Note the "!" - it tells System.Mail to delete the attached file after emailing.

A list of all variables is here:

Title: Re: Email to filename
Post by rowman25 on May 3rd, 2013 at 8:42pm
Thank you.  The info you have given have gotten it to work how I am hoping, however, it has given me more questions about additional possibilities.  

I notice in the postman set up that you could assign a file to be appended to the email.  I am wondering if the file that I save to the directory is a text or HTML file, if the variables for the filename can be used in assigning the file to append to the email?

Does it make sense what I am asking?

Title: Re: Email to filename
Post by Gert on May 4th, 2013 at 8:07am
Insert the following somewhere the message body is build, for example just after

Code (]echo best regards, >> "%EMAILFILE%"

You can enter this:
[code]IF "%WD_FILE_E%" EQU "TXT" type "%WD_FILE%" >> "%EMAILFILE%"

Title: Re: Email to filename
Post by rowman25 on May 4th, 2013 at 10:59pm
Wow. You know this stuff really well.  So everything is looking good at this point except I am having trouble coming up with a way to covert the contents of the PDF file to HTML.  To explain what my workflow looks like right now is:

* Print the receipt to PDF and save to the watched folder
* Some kind of automated process to convert the PDF to HTML (I can do this by opening Adobe Acrobat 8.0 and saving as HTML but can Watch directory automate this step or do I need a different macro program?)
* Watch Directory sees the HTML file and attaches the PDF but also appends the contents of the HTML file to the email.

I also read up on encoding the header so it can send an HTML email.  Can you tell me where I would include the <HTML> tag in the bat file?

WatchDirectory Forum » Powered by YaBB 2.5.2!
YaBB Forum Software © 2000-2017. All Rights Reserved.