【问题标题】:command work in command prompt but not in batch file命令在命令提示符下工作,但不在批处理文件中
【发布时间】:2013-05-28 00:47:10
【问题描述】:

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

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.

我检查过了。没有错字,有人可以帮我看看有什么区别吗?为什么相同的命令在命令行中有效,但在脚本文件中引起问题?

谢谢

【问题讨论】:

  • 你在使用延迟扩展吗?
  • 是的,你拯救了我的一天!我确实把它放在了开头,一旦删除,问题就解决了!非常感谢!

标签: command-line batch-file smtp sendmail


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

【讨论】:

  • 感谢您的回答,问题是我使用了延迟扩展。删除后一切正常!
猜你喜欢
  • 1970-01-01
  • 2013-08-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-03-17
  • 2013-11-08
相关资源
最近更新 更多