sending email from dat file problem

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
johnob
Posts: 4
Joined: 16 Jan 2014 08:33

sending email from dat file problem

#1 Post by johnob » 16 Jan 2014 08:47

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

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: sending email from dat file problem

#2 Post by Squashman » 16 Jan 2014 08:55

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.

johnob
Posts: 4
Joined: 16 Jan 2014 08:33

Re: sending email from dat file problem

#3 Post by johnob » 16 Jan 2014 09:01

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

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: sending email from dat file problem

#4 Post by foxidrive » 16 Jan 2014 09:02

You can also create a temporary text file using echo commands, if your email program supports an external file.

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: sending email from dat file problem

#5 Post by Squashman » 16 Jan 2014 09:06

That didn't answer my question. Batch files cannot send emails without some other program to do it. What program is sending the email?

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: sending email from dat file problem

#6 Post by Squashman » 16 Jan 2014 09:08

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.

johnob
Posts: 4
Joined: 16 Jan 2014 08:33

Re: sending email from dat file problem

#7 Post by johnob » 16 Jan 2014 09:10

sorry

its windows live mail

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: sending email from dat file problem

#8 Post by foxidrive » 16 Jan 2014 09:15

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

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: sending email from dat file problem

#9 Post by Squashman » 16 Jan 2014 09:39

His code does look like the start of your hybrid script.

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: sending email from dat file problem

#10 Post by Squashman » 16 Jan 2014 09:40

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.

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: sending email from dat file problem

#11 Post by Squashman » 16 Jan 2014 11:33

If you are using Foxidrive's hybrid batch/vb email script you should be able to do this.

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.

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: sending email from dat file problem

#12 Post by penpen » 16 Jan 2014 13:32

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

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:
johnob wrote:set Body="Hello%0D%0AThis%20is the new update.%0D%0Please Install%0D%0Thank you"
this output:
johnob wrote: Hello
This is the new update.
Please Install
Thank you
According to the webpage above, i'm sure you wanted to get the following output johnob:

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.

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: sending email from dat file problem

#13 Post by Squashman » 16 Jan 2014 14:05

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.

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: sending email from dat file problem

#14 Post by Squashman » 16 Jan 2014 14:29

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.

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

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: sending email from dat file problem

#15 Post by penpen » 16 Jan 2014 15:08

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 :cry: );
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

Post Reply