简体   繁体   中英

command work in command prompt but not in batch file

I am trying to send out email attachment periodically from a batch script using this command line client

http://caspian.dotconf.net/menu/Software/SendEmail

the command for it is pretty straightforward

sendEmail -t abc@gmail.com -u hellp -f abd@nus.edu.sg -m world -s smtp.nus.edu.sg -xu nusstu\a123456 -xp helloworld! -a C:\Users\ll\Desktop\Quotes.docx

The strange thing is if I type that line in command prompt, it works perfectly fine. I can receive the email with attachment.

However, when I put it into a batch script, like

:email
sendEmail -t abc@gmail.com -u hellp -f abd@nus.edu.sg -m world -s smtp.nus.edu.sg -xu       nusstu\a123456 -xp helloworld! -a C:\Users\ll\Desktop\Quotes.docx
goto:eof

and I call this subroutine in my batch file, the output says

SMTP:AUTH authentication to smtp.nus.edu.sg:25 failed.

I checked. no typo, Could someone help me what is the difference? why the same command works in command line but cause trouble in a script file?

Thanks

I believe you're censoring your batch too much.

Try running the following:

@ECHO OFF

setlocal
echo sendEmail -t abc@gmail.com -u hellp -f abd@nus.edu.sg -m world -s smtp.nus.edu.sg -xu nusstu\a123456 -xp helloworld! -a C:\Users\ll\Desktop\Quotes.docx
endlocal

SETLOCAL enabledelayedexpansion
echo sendEmail -t abc@gmail.com -u hellp -f abd@nus.edu.sg -m world -s smtp.nus.edu.sg -xu nusstu\a123456 -xp helloworld! -a C:\Users\ll\Desktop\Quotes.docx
echo sendEmail -t abc@gmail.com -u hellp -f abd@nus.edu.sg -m world -s smtp.nus.edu.sg -xu  nusstu\a123456 -xp helloworld^^! -a C:\Users\ll\Desktop\Quotes.docx
goto:eof

Because your password contains ! , batch interprets that as a variable-name if DELAYEDEXPANSION is invoked. Since the variablename isn't set, it's replaced by [nothing] and sendtoemail believes that your password is helloworld\\Users\\ll\\Desktop\\Quotes.docx - hence the error message.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM