繁体   English   中英

命令在命令提示符下工作,但不在批处理文件中

[英]command work in command prompt but not in batch file

我正在尝试使用此命令行客户端定期从批处理脚本发送电子邮件附件

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

该命令非常简单

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

奇怪的是,如果我在命令提示符下键入该行,则效果很好。 我可以收到带有附件的电子邮件。

但是,当我将其放入批处理脚本时,例如

: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

然后在批处理文件中调用此子例程,输出显示

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

我检查了。 没有错字,有人可以帮我有什么区别吗? 为什么同一命令在命令行中有效,但在脚本文件中引起麻烦?

谢谢

我相信您对您的批次检查过多。

尝试运行以下命令:

@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

因为您的密码包含! ,如果调用DELAYEDEXPANSION,则批处理将其解释为变量名。 由于未设置变量名,因此将其替换为[nothing],并且sendtoemail认为您的密码为helloworld\\Users\\ll\\Desktop\\Quotes.docx因此出现错误消息。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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