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

时间:2013-06-01 07:12:11

标签: command-line batch-file smtp sendmail

我正在尝试使用此命令行客户端

定期从批处理脚本发送电子邮件附件

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.
我检查了一下。没有错字,有人可以帮助我有什么区别吗?为什么同一个命令在命令行中工作但在脚本文件中引起麻烦?

由于

1 个答案:

答案 0 :(得分:1)

我相信你过多地审查你的批次。

尝试运行以下内容:

@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,批处理会将其解释为变量名。由于未设置variablename,因此将其替换为[nothing],sendtoemail认为您的密码为helloworld\Users\ll\Desktop\Quotes.docx - 因此出现错误消息。