1.

Solve : send a .txt file from a batch to mail box?

Answer»

Hi Guys,

Is it possible send a .txt file to a mail box (and then sen it with outlook) directly from a BATCH file?

Thaks,
CIAO
RiccardoThere are probably 3rd party products that will let you do this from a batch file (try googling for them) otherwise you can use a script:

Code: [Select]
Set objEmail = CreateObject("CDO.Message")
objEmail.From = "youremailaddress.com"
objEmail.To = "recipientsmailaddress.com"
objEmail.Subject = "subject"
objEmail.Textbody = "Body"
objEmail.AddAttachment "attachfilename"
objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configurati
on/sendusing") = 2
objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configurati
on/smtpserver") = "yourmailserver"
objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configurati
on/smtpserverport") = 25
objEmail.Configuration.Fields.Update
objEmail.Send


In the from parameter, put your email address. In the to parameter, list the addresses of who you're sending the email. Separate with semi-colons if multiple addresses. In subject and body put anything appropriate. In the attachments parameter put the path and file name of your file. In the smtpserver parameter, put your email servername. You may have to check with your ISP for this info, although most ISP's have this info on their web sites. Do not change the rest of the parameters.

Save the file with a VBS extension and run from the command line as cscript scriptname.vbs

Good luck.

This question has been asked and answered numerous times before. Please research your question before posting.Thanks SideW

I'll try.

thake care
RiccardoSideW, or who want to help,

What if i try to call the Vbs script with the "call" command from the batch file?

thanks,

Riccardoif the script is correct, that should work... (the call command) how to use it

call [drive][directory]
example: c:/test.vbsHi SideW

When i run the script i got an error like this:

*.vbs(7, 82) Microsoft VBSCRIPT Compilation Error: string without termination.

What can it be?

Ciao
RiccardoApparently you ran into a limitation of the forum. Some of the lines you see as two lines were written and need to be just one line unless you use continuation.

All lines preceeded by: objEmail.Configuration.Fields.Item (and followed by another line) need to be one line in your editor.

Hope this helps. Ciao SideW,

Yes you were right, actually i found it few second after i posted it.... sorry for bother you for such a stupid thing.

but now when i run it i have this error msg:

*.vbs(6, 1) CDO.Message.1: the specified protocol is unknow


This is the 6TH line :
objEmail.AddAttachment "ciao_12.txt"

For wich reason should be the protocol Unknow?

Ciao
RicYou need to use a fully qualified file name for the attachment.

Example: "drive:\dir1\dir2\ciao_12.txt"

Hope this helps. ...getting closer,

Yuor last tip worked, but now look at this, it seems like the mail server doesn't GET the command :

*.vsb (11,1) (null): the message could not been sent to the SMTP server.
0217. the server response was not available

ciao
RicYou may have missed the instructions that went along with the code:
Quote

In the from parameter, put your email address. In the to parameter, list the addresses of who you're sending the email. Separate with semi-colons if multiple addresses. In subject and body put anything appropriate. In the attachments parameter put the path and file name of your file. In the smtpserver parameter, put your email servername. You may have to check with your ISP for this info, although most ISP's have this info on their web sites. Do not change the rest of the parameters.

You didn't post your script so my guess is that the smtpserver parameter is in error. Do you host your own email? If you do check with your network administrator or else you may have to check with your ISP for details.



Discussion

No Comment Found