WatchDirectory home page
WatchDirectory Startseite (Deutsche Version)
Site WatchDirectory (Français)
  Welcome, Guest. Please Login or Register
YaBB - Yet another Bulletin Board
   
  HomeHelpSearchLoginRegister  
 
Page Index Toggle Pages: 1
Email to filename (Read 5807 times)
rowman25
YaBB Newbies
*
Offline



Posts: 6
Email to filename
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 recipient@gmail.com.pdf I want the file to be mailed as an attachment to recipient@gmail.com.

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.
Back to top
 
 
IP Logged
 
Gert
YaBB Administrator
*****
Offline



Posts: 2233
The Netherlands
Re: Email to filename
Reply #1 - 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 ( http://www.watchdirectory.net/wdhelp/plugins/wdopAutoRunBat.html ) and send the email from the bat file ( http://www.watchdirectory.net/wdhelp/plugins/wdopAutoRunBatEmail.html ).

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

Gert Rijs - gert (at) gdpsoftware (dot) com
Blog: http://blog-en.gdpsoftware.com/
End Alzheimer's: http://www.alz.org&&...
WWW WWW GdPSoftware  
IP Logged
 
rowman25
YaBB Newbies
*
Offline



Posts: 6
Re: Email to filename
Reply #2 - 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.
Back to top
 
 
IP Logged
 
Gert
YaBB Administrator
*****
Offline



Posts: 2233
The Netherlands
Re: Email to filename
Reply #3 - Mar 12th, 2013 at 10:17am
 
Hi,

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:
Code:
set EMAILFILE=%WD_TASKDIR%\..\System.Mail\Out\%WD_CONFIG%_%WD_CUREVT%.TMP

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%"
echo    %COMPUTERNAME% >> "%EMAILFILE%"

rem okay, the script is created, now rename it so the wdPostMan program processes it.
ren "%EMAILFILE%" %WD_CONFIG%_%WD_CUREVT%.wdmail
 



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.
Back to top
 

Gert Rijs - gert (at) gdpsoftware (dot) com
Blog: http://blog-en.gdpsoftware.com/
End Alzheimer's: http://www.alz.org&&...
WWW WWW GdPSoftware  
IP Logged
 
rowman25
YaBB Newbies
*
Offline



Posts: 6
Re: Email to filename
Reply #4 - 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.
Back to top
 
 
IP Logged
 
rowman25
YaBB Newbies
*
Offline



Posts: 6
Re: Email to filename
Reply #5 - 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.

Thanks.
Back to top
 
 
IP Logged
 
Gert
YaBB Administrator
*****
Offline



Posts: 2233
The Netherlands
Re: Email to filename
Reply #6 - 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:
[code]COPY "%WD_FILE%" "%WD_TASKDIR%\%WD_CUREVT%_%WD_FILE_N%"
IF %errorlevel% GEQ 1 GOTO :EOF
DEL "%WD_FILE%"
[/code]
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%"[/code]
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:
http://www.watchdirectory.net/wdhelp/plugins/wdopAutoRunBatEnv.html
Back to top
 

Gert Rijs - gert (at) gdpsoftware (dot) com
Blog: http://blog-en.gdpsoftware.com/
End Alzheimer's: http://www.alz.org&&...
WWW WWW GdPSoftware  
IP Logged
 
rowman25
YaBB Newbies
*
Offline



Posts: 6
Re: Email to filename
Reply #7 - 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?
Back to top
 
 
IP Logged
 
Gert
YaBB Administrator
*****
Offline



Posts: 2233
The Netherlands
Re: Email to filename
Reply #8 - May 4th, 2013 at 8:07am
 
Insert the following somewhere the message body is build, for example just after
Code:
echo best regards, >> "%EMAILFILE%"
echo    %COMPUTERNAME% >> "%EMAILFILE%"
 


You can enter this:
Code:
IF "%WD_FILE_E%" EQU "TXT" type "%WD_FILE%" >> "%EMAILFILE%"
IF "%WD_FILE_E%" EQU "HTML" type "%WD_FILE%" >> "%EMAILFILE%"
 

Back to top
 

Gert Rijs - gert (at) gdpsoftware (dot) com
Blog: http://blog-en.gdpsoftware.com/
End Alzheimer's: http://www.alz.org&&...
WWW WWW GdPSoftware  
IP Logged
 
rowman25
YaBB Newbies
*
Offline



Posts: 6
Re: Email to filename
Reply #9 - 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?
Back to top
 
 
IP Logged
 
Page Index Toggle Pages: 1