Pages: 1
RSS
Can theBat! take a file and email it?
 
Can theBat! take a file, from a folder, extract the email address from the file name and email it to that email address?
 
theBat can't, but you can.

You can make a .vbs or .wsh script that takes the email from the file name, then modifies a text file(message template) to set the recipient and the file to be attached, and then sends a command to theBat to send the message.
If you know vbs or wsh, this will take you not more than half an hour.
 
The Bat! can!

Open scheduller and in task properties, click to Actions tab and add "Watch and Send files" item, where You can select what to check and which account will be used for sending mail.
 
Thanks for your message titled: TheBat! can!

I don't understand what you mean by "where You can select what to check and which account will be used for sending mail."

I have a program that automatically proccesses documents, and once processed the processed files are sent to an Output Directory. I'd like to use TheBat! to take each file, from the Output Directory folder, extract the email address from the file name and email it (the file) to that email address automatically?

And you are saying theBat! can do this automatically?
Or do I need to manually do this with TheBat!?

Thank you I look forward to your reply.
 
in dialog for "Watch and Send files" action You can select which directory and which files will pro processed, You have checkbox for creating one message per file and on second tab, You can select which account and which address will be used.

Only missing thing seems to be extracting emails from filename...

BTW if are filenames and addresses same, You can do this with commandline parameter /MAIL, where You can define filename, address, folder etc.
 
Thank you again for all of your your help.

I appreciate your assistance, but could you clarify what you mean by "you can do this with commandline parameter /MAIL, where you can define filename, address, folder etc.".

I'm not familiar with "commandline parameter /MAIL".
But I've looked at the information in TheBat! help section and copied it below. I'm just not too sure how to use this information correctly.

If you would be so kind as to assist me with this, I'd greatly appreciate it.

The Folder named OutPut is the one that is using the "Watch and Send Files" action.

When a file arrives into the OutPut folder, named anyname@yahoo.com.txt, how can I use the commandline paramter info to extract the email address from the file name and email it (the file) to that extracted email address automatically?

Thank you. I look forward to any assistance.

The /MAIL command is used for automated message creation using a template, text file and/or set of attached files for a specific destination address. This command is extremely useful for applications that need to send e-mail messages without having to do the additional work involved in the implementation of the various Internet e-mail standards.

Syntax

/MAIL[parameter1[;parameter2[;parameter3[...]]]

Parameters

USER=value or U=value
value is the name of the source account. If no FOLDER parameter is specified, the target folder will be the Inbox of the given account.

PASSWORD=value or P=value
value is the password which will unlock the account if it is needed.

FOLDER=value or F=value
value is the target folder's pathname. If the pathname does not include an account name, The Bat! will search all accounts for a folder with a matching name; the first folder found will be used as the target folder. If the specified folder is not found, the Outbox folder of the target account is used.

TEMPLATE=value or T=value
value is the pathname of the file which contains the template that will be used for the creation of the message. By default, it is the standard template of the target folder or the target account.

TO=value
value specifies the primary addressee of the message. You can add additional addressees using template macros %TO, %CC, %BCC.

SUBJECT=value or S=value
value specifies the subject of the message. It is also possible to define the message subject in the template using %SUBJECT macros.

TEXT=value or  CONTENTS=value or C=value
value is the pathname of a plain text file which contains the text of the message. It is also possible to include a text file into a message using the %PUT macro in the template.

ATTACH=value or  FILE=value or A=value
value is the pathname of the file which will be attached to the message. It is also possible to use %ATTACHFILE macros in the template.

SEND
if this parameter is used, the created message will be sent out as soon as it has been created.

QUEUE
if this parameter is used, the created message will be queued in the Outbox once it is created.

EDIT
if this parameter is used, The Bat! opens the editor with the message created using the parameters from above

Examples

/MAILU=MyAccount;TO=some@address.com;S=Test;TEXT=C:\TESTs\TEST.MSG

/MAILF=\\MyAccount\Test;TO=some@address.com

Note: To separate parameters, use semicolons (";" characters). Do not put spaces between parameters when using the  /EXPORT command from the command line because a space-separated mask will be interpreted as the next command line parameter and will not be processed as intended.        

Note: If a parameter value contains space characters, enclose it in quotation marks. If a value contains quotation marks, you should use single quotes (" ' " characters).      

 
I don't think TB alone can pick the recipient address from the file name, that's why you'll need something additional - most simple would be a vbs file that makes something like this:

-enumerate all files in the output folder that match a given pattern, like "\*@*.txt"

#For each file found
> determine recipient by replacing ".txt" with nothing in the filename
> rename the file, replace "@" with "_" in the filename, so that you don't process it again next time
> build a command to TB, using recipient and path to renamed file as parameters. You may use the QUEUE switch so that message remains in the outbox
>execute the command
#end of cycle

-Now send another command to TB to send all messages

Schedule the vbs file to run every 10 minutes or so, using the Windows scheduler
 
Hi,

Thanks for your reply.

I don't think the script you're referring to would need to "enumerate all files". But I could be wrong. All files that arrive into the output directory will have the same pattern, which will be email@emailaddress.com (or net, etc.).txt

And renaming the file, may not be neccesary because theBat! Action Scheduler automatically moves the file, once sent, to another folder, thus removing the chance of "processing it again next time".

You then stated "build a command to TB, using recipient and path to renamed file as parameters".

Since we may not need to rename or enumerate the file, can I build a command using the parameter info shown in my message above to accomplish my goal of
sending the file to the email address in the file name? Or do I still need a vbs script? (I'm no expert, I'm learning as I go here.)

If I don't need a vbs script, can someone help me with a parameter command line info to complete my goal?

Thank you. I look forward to being enlightened.

 
I've tried several things, in order to have TB extract the addressee from the attached file with some regular expression in an template.
However, whatever I tried TB executes the template before the file is attached. :-(
Therefore I came with this workaround, I started TB with the /Mail parameter and set the file name as To address, TB doesn't care whether the specified address is valid or not, but it takes it and executes the template. In that template I used some regexp to correct the address.
I'm using two files to achieve this, a sendfile.cmd containing one single line:
For %%i in (c:\temp\*.txt) do "C:\Program Files\The Bat!\thebat.exe" /MailT=C:\temp\Sendfile.tpl;A="%%i";To="%%i";A="%%i";Send
And a sendfile.tpl, as template. Containing this:
-----Start of Sendfile.tpl-------------
%SetPattRegExp='C:\\Temp\\(.*?)\.txt'%-
%RegExpBlindMatch='%To'%-
%ModifyOnce(To)%-
%SetHeader(To,%SubPatt='1')%-
Hi %ABToFirstName="%ToFName",

I hope you like this.

Regards, %FromFName
------End of Sendfile.tpl--------------
Notes:
I stored the sendfile.cmd, sendfile.tpl and the files I wanted to send in the directory C:\Temp, you can change that, but in that case you need to change the path in the .cmd and the .tpl
In the regexp in the .tpl you'll notice that the backslashes in the path are doubled, that's because the backslash is a special character, so I needed to escape it. the same goes for the dot before the txt extension, so I neeed to make that literal with a backslash.
My preferred method of executing the cmd file would be to do that from some scheduler, whether that's the one from Windows, TB or some third party doesn't really matter.
I intentially didn't handle the part of moving/deleting/renaming the sent files in the sendfile.cmd. When you execute the sendfile.cmd from the Windows Scheduler while TB was closed, you'll find that the files are deleted before TB was ready to send them. So my preferred method would be to achieve this via a sent messages filter. In order to make this simple I set the subject of the sent messages to contain the full path of the attachment.

I've tested both the regexp and the cmd of the posted solution. My only alteration was that I added the Send parameter after the testing, as I didn't want to send the files myself.
__________________________________
I'm just a user of The Bat! I don't work for Ritlabs.
 
Thank you so much for your kind assistance. I greatly appreciate your solution.

However, I am not as advanced as you in the ways of files and executing those files. So, if you would be so kind as to allow me to ask a few questions so I may attempt to execute your solution. I would greatly appreciate your expertise once again.

I have stored your cmd and tpl files in the directory where the files are stored, which is Documents and Settings\My Documents\Output and so I have changed your files to:
For %%i in (c:\Documents and Settings\My Documents\Output*.txt) do "C:\Program Files\The Bat!\thebat.exe" /MailT=C:\Documents and Settings\My Documents\Output\Sendfile.tpl;A="%%i";To="%%i";A="%%¬i";Send

and

-----Start of Sendfile.tpl-------------
%SetPattRegExp='C:\\Documents and Settings\My Documents\Output\\(.*?)\.txt'%-
%RegExpBlindMatch='%To'%-
%ModifyOnce(To)%-
%SetHeader(To,%SubPatt='1')%-
Hi %ABToFirstName="%ToFName",

I hope these look correct with my changes.

You stated:
"I started TB with the /Mail parameter"

How/where can I "start TB with the /Mail parameter"?
I'm just not familiar with this, thanks.

You then stated:
"and set the file name as To address"
I'm not sure, how and where I can do this. Can you please tell me?
Also, which file name are you referring to?

You also stated:
"I set the subject of the sent messages to contain the full path of the attachment"
Could you please tell me how to accomplish this?

Additionally you stated:
"I added the Send parameter after the testing"
Help or clarification for "adding the Send parmeter" how and where, would be greatly appreciated.

Also, please, how do I execute the cmd file using theBat! scheduler?
I've set a "Watch and Send Files" action with TB, that's the extent of my experience.

Thanks so much. I hope this is not a problem clarifying these things for me. I truly appreciate your expertise nand kind assistance.
 
Change the Sendfile.cmd into this:

For %%i in ("C :\Documents and Settings\My Documents\Output\*.txt") do "C:\Program Files\The Bat!\thebat.exe" /MailT="C:\Documents and Settings\My Documents\Output\Sendfile.tpl";A="%%i";To="%%i";S="­%%i";Send

You're using paths with spaces in the directory names, nothing wrong with that, but in that case you need to enclose the path between quotation marks, so I've added those. Second I added a backslash between Output and *.txt as I understood from your other messages that you're using a directory named 'Output' and that it isn't part of the file name. Also I deleted an odd character that you managed to insert in the last instance of %%i. And finally I corrected a typo of mine, the second A= needed to be an S=

The line of the template needs to be changed into:
%SetPattRegExp='C:\\Documents and Settings\\My Documents\\Output\\(.*?)\.txt'%-
as all backslashes in the path need to be escaped for a proper functioning of the regexp.

Your questions regarding the parameters, I merely explained what the parameters I used in the .cmd file were doing.

The .cmd file can be split into two parts. The condition, that's the part between 'For' and 'do' and the action, that's the part after 'do'.
Discussing For loops in batch files falls outside the topic of this forum, so I'll keep to the action part:
"C:\Program Files\The Bat!\thebat.exe" /MailT="C:\Documents and Settings\My Documents\Output\Sendfile.tpl";A="%%i";To="%%i";A="­%%i";Send

The first part is easy, that's the full path to your TB executable, between quotation marks, due to the spaces in the path.
The second part is a parameter that Windows will pass to the executed program.
It starts with /Mail, so TB knows it has to create a message.
/Mail is followed by T=, so TB knows the path leads to a file that has to be interpreted as a template.
After the template path a semi colon is followed by A=, so TB knows the message has an attachment
After the attachment there's the To= part that defines the recipient (that I overrule that recipient in the template doesn't matter)
Further on you'll find an S= to define the subject
Finally there's the Send part that tells TB to send the created message immediately in stead of storing it in the Outbox.
All of these subparameters are separated by semicolons, just as the help file said in the part that you quoted.
Windows will substitute all instances of %%i by the proper path and file name.

You execute this with TB's scheduler by creating a new schedule and set as action 'Start a command', this will lead you to a pop-up that tells you to browse to the program (the sendfile.cmd in this case) that you want to execute.
__________________________________
I'm just a user of The Bat! I don't work for Ritlabs.
 
Thank you. It works great. You're brilliant!
I greatly appreciate your expertise and kind assistance.
Cheers.
 
I do have an issue with the extract email address/send file solution in this thread.
Any help will be appreciated.

It works fine, but then I noticed all files were being sent to the same email address.

I opened theBat! Scheduler looked under my Watch and Send Files action > Mailings > Create Message for >
I had a Specific Address listed, which all sent files were going to.

So, naturally I selected the only other choice Linked Persons/Addresses, and ran the program without success. The files are not going to the email addresses of the file names.

I look forward to remedying this with your assistance.

Thanks.
Pages: 1