sending email from dat file problem
Moderator: DosItHelp
sending email from dat file problem
Hi all,
Im trying to get the body text on an email to set out correctly, but can't seem to get it working right.
What im trying to do ands what result happens .
command line ..
set Body="Hello%0D%0AThis is the new update.%0D%0Please Install%0D%0Thank you"
What i want is ..
Hello
This is the new update.
Please Install
Thank you
But what i get is ..
Hello:menu_5D:menu_5AThis is the new update.:menu_5D:menu_5APlease Install:menu_5D:menu_5AThank you
Can anyone help ?
Thank you
John
Im trying to get the body text on an email to set out correctly, but can't seem to get it working right.
What im trying to do ands what result happens .
command line ..
set Body="Hello%0D%0AThis is the new update.%0D%0Please Install%0D%0Thank you"
What i want is ..
Hello
This is the new update.
Please Install
Thank you
But what i get is ..
Hello:menu_5D:menu_5AThis is the new update.:menu_5D:menu_5APlease Install:menu_5D:menu_5AThank you
Can anyone help ?
Thank you
John
Re: sending email from dat file problem
What program are you using to send the email. I have never seen syntax like that to make a CRLF.
We have specific code on the forums to put a CR and LF into a variable.
We have specific code on the forums to put a CR and LF into a variable.
Re: sending email from dat file problem
here is some of the code :
::email-bat.cmd:::::::::::::::::::::::::::::::::::::::::::::::::::::
@echo off
setlocal
:: defaults
set From=********@btinternetcom
set To=*********@btinternetcom
set Subj="New Update %date% %time%"
set Body="Hello%0D%0AThis is the new update.%0D%0Please Install%0D%0Thank you"
set Serv=mail.btinternetcom
set Auth=********@btinternetcom
set Pass=*****
set fileattach=C:\Users\John\Desktop\Update.pdf
::email-bat.cmd:::::::::::::::::::::::::::::::::::::::::::::::::::::
@echo off
setlocal
:: defaults
set From=********@btinternetcom
set To=*********@btinternetcom
set Subj="New Update %date% %time%"
set Body="Hello%0D%0AThis is the new update.%0D%0Please Install%0D%0Thank you"
set Serv=mail.btinternetcom
set Auth=********@btinternetcom
set Pass=*****
set fileattach=C:\Users\John\Desktop\Update.pdf
Re: sending email from dat file problem
You can also create a temporary text file using echo commands, if your email program supports an external file.
Re: sending email from dat file problem
That didn't answer my question. Batch files cannot send emails without some other program to do it. What program is sending the email?
Re: sending email from dat file problem
foxidrive wrote:You can also create a temporary text file using echo commands, if your email program supports an external file.
Yes. You can do the same thing with the VBscript email. You can read the contents of the file into a variable and use that as the body of the email.
Re: sending email from dat file problem
sorry
its windows live mail
its windows live mail
Re: sending email from dat file problem
johnob wrote:here is some of the code :
::email-bat.cmd:::::::::::::::::::::::::::::::::::::::::::::::::::::
@echo off
setlocal
:: defaults
set From=********@btinternetcom
set To=*********@btinternetcom
set Subj="New Update %date% %time%"
set Body="Hello%0D%0AThis is the new update.%0D%0Please Install%0D%0Thank you"
set Serv=mail.btinternetcom
set Auth=********@btinternetcom
set Pass=*****
set fileattach=C:\Users\John\Desktop\Update.pdf
I wrote a batch file that looks like this - it doesn't use Windows Live Mail.

Code: Select all
::email-bat.cmd:::::::::::::::::::::::::::::::::::::::::::::::::::::
@echo off
setlocal
:: defaults
set From=me@here.com.au
set To=you@lavabit.com
set Subj="email test %date% %time%"
set Body="did it work? %date% %time%"
set Serv=mail.server.com.au
set Auth=user
set Pass=pass
set fileattach=
:: if command line arguments are supplied then use them
if "%~7" NEQ "" (
set From=%1
set To=%2
set Subj="%~3"
set Body="%~4"
set Serv=%5
set "Auth=%~6"
set "Pass=%~7"
set "fileattach=%~8"
)
call :createVBS "email-bat.vbs"
call :send %From% %To% %Subj% %Body% %Serv% %Auth% %Pass%
echo email sent (if parameters were correct)
pause
del "%vbsfile%" 2>nul
goto :EOF
:send
cscript.exe /nologo "%vbsfile%" %1 %2 %3 %4 %5 %6 %7
goto :EOF
:createVBS
set "vbsfile=%~1"
del "%vbsfile%" 2>nul
set cdoSchema=http://schemas.microsoft.com/cdo/configuration
echo >>"%vbsfile%" Set objArgs = WScript.Arguments
echo >>"%vbsfile%" Set objEmail = CreateObject("CDO.Message")
echo >>"%vbsfile%" objEmail.From = objArgs(0)
echo >>"%vbsfile%" objEmail.To = objArgs(1)
echo >>"%vbsfile%" objEmail.Subject = objArgs(2)
echo >>"%vbsfile%" objEmail.Textbody = objArgs(3)
if defined fileattach echo >>"%vbsfile%" objEmail.AddAttachment "%fileattach%"
echo >>"%vbsfile%" with objEmail.Configuration.Fields
echo >>"%vbsfile%" .Item ("%cdoSchema%/sendusing") = 2 ' not local, smtp
echo >>"%vbsfile%" .Item ("%cdoSchema%/smtpserver") = objArgs(4)
echo >>"%vbsfile%" .Item ("%cdoSchema%/smtpserverport") = 25
echo >>"%vbsfile%" .Item ("%cdoSchema%/smtpauthenticate") = 1 ' cdobasic
echo >>"%vbsfile%" .Item ("%cdoSchema%/sendusername") = objArgs(5)
echo >>"%vbsfile%" .Item ("%cdoSchema%/sendpassword") = objArgs(6)
echo >>"%vbsfile%" .Item ("%cdoSchema%/smtpusessl") = False
echo >>"%vbsfile%" .Item ("%cdoSchema%/smtpconnectiontimeout") = 30
echo >>"%vbsfile%" .Update
echo >>"%vbsfile%" end with
echo >>"%vbsfile%" objEmail.Send
:end
Re: sending email from dat file problem
His code does look like the start of your hybrid script.
Re: sending email from dat file problem
johnob wrote:sorry
its windows live mail
I could be wrong but I have never seen Windows Live Mail work from a batch file to send emails.
Re: sending email from dat file problem
If you are using Foxidrive's hybrid batch/vb email script you should be able to do this.
In theory it should work. Not sure if we need to escape the ampersand one more time or not because we are passing the variable to another function.
Code: Select all
set Body="Hello" ^& VBcrlf ^& "This is the new update." ^& vbcrlf ^& "Please Install" ^& VBcrlf ^& "Thank you"
In theory it should work. Not sure if we need to escape the ampersand one more time or not because we are passing the variable to another function.
Re: sending email from dat file problem
It is possible to use Windows Live Mail within a batch file to send an email:
http://email.about.com/od/outlookexpresshacks/qt/Command_Line_Mail_in_Windows_Live_Mail_or_Outlook_Express.htm
But i assume the OP didn't wanted to get from this input:
So it seems, that you only need to escape the '%' characters with "%%", so this seems to be what you need:
You may use this to get the right string for the email:
http://email.about.com/library/misc/blmailto_encoder.htm
penpen
Edit: Added the mailto url-encoder link.
http://email.about.com/od/outlookexpresshacks/qt/Command_Line_Mail_in_Windows_Live_Mail_or_Outlook_Express.htm
Code: Select all
"C:\Program Files\Windows Live\Mail\wlmail" /mailurl:mailto:mailto:me%40mail.com?subject=blabla&body=Hi
But i assume the OP didn't wanted to get from this input:
this output:johnob wrote:set Body="Hello%0D%0AThis%20is the new update.%0D%0Please Install%0D%0Thank you"
According to the webpage above, i'm sure you wanted to get the following output johnob:johnob wrote: Hello
This is the new update.
Please Install
Thank you
Code: Select all
Hello%0D%0AThis%20is%20the%20new%20update.%0D%0APlease%20Install%0D%0AThank%20you
So it seems, that you only need to escape the '%' characters with "%%", so this seems to be what you need:
Code: Select all
set "body=Hello%%0D%%0AThis%%20is%%20the%%20new%%20update.%%0D%%0APlease%%20Install%%0D%%0AThank%%20you"
You may use this to get the right string for the email:
http://email.about.com/library/misc/blmailto_encoder.htm
penpen
Edit: Added the mailto url-encoder link.
Re: sending email from dat file problem
Aah, I see now but you can't send the email automatically. It just opens up the email in Windows Live Mail and you still have to send it from there.
Seems like it would be easier to create it all on one line instead of assigning variables and then putting those variables into the one line.
Seems like it would be easier to create it all on one line instead of assigning variables and then putting those variables into the one line.
Re: sending email from dat file problem
Penpen, the link you provided also says that you cannot attach files. Yet the code that John posted is clearly from one of the bat files that we have posted on Dostips.com and he is trying to Set the Server, Auth, Password and Attach variables.
I think he may be confused on what he is trying to do. Does he want a fully automated email or does he want to create an email within Windows Live Mail.
I think he may be confused on what he is trying to do. Does he want a fully automated email or does he want to create an email within Windows Live Mail.
johnob wrote:here is some of the code :
::email-bat.cmd:::::::::::::::::::::::::::::::::::::::::::::::::::::
@echo off
setlocal
:: defaults
set From=********@btinternetcom
set To=*********@btinternetcom
set Subj="New Update %date% %time%"
set Body="Hello%0D%0AThis is the new update.%0D%0Please Install%0D%0Thank you"
set Serv=mail.btinternetcom
set Auth=********@btinternetcom
set Pass=*****
set fileattach=C:\Users\John\Desktop\Update.pdf
Re: sending email from dat file problem
I've overseen the "set fileattach=..." part: Yes, this is impossible.
But i think i remember that there is a command line option for sending the mail... (but i don't remember, and googling is of nut much success
);
maybe "/send" or "/mail", or something like that... and you must have set up a (default) user in windows live (password, ports, ...).
But i thinks, the VBS solution is preferable, too, as you have more control.
penpen
But i think i remember that there is a command line option for sending the mail... (but i don't remember, and googling is of nut much success

maybe "/send" or "/mail", or something like that... and you must have set up a (default) user in windows live (password, ports, ...).
But i thinks, the VBS solution is preferable, too, as you have more control.
penpen