Windows编程-发送电子邮件脚本
正在寻找一个可以在 Windows 2003 服务器上运行的简单脚本,该脚本基本上可以向我发送电子邮件。我计划使用 Windows 服务自动恢复管理器来触发脚本。
我确实找到了如何触发使用此脚本的参考:如何监视 Windows 服务< /a>
但我需要一些帮助来编写适用于 Windows 平台的发送电子邮件脚本。我不确定哪种语言最适合这个。谢谢。
Looking for a simple script that would run on windows 2003 server that would basically send me an email. What I plan to do us the windows services auto recovery manager to trigger the script.
I did find a reference to how I can trigger the use of this script: How to monitor Windows services
But I need some help on writing an send email script that would work for windows platform. I'm not sure what language would be best for this. thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一种简单的方法是使用 javascript(或 VBscript)。如果您在 google 上搜索“Server.CreateObject("CDO.Message")”,您会找到更多示例。
将下面的代码放在扩展名为“.js”的文件中,例如 email.js
要调用,请在命令行上使用“cscript email.js”。将服务器名称和电子邮件替换为有效值。
Windows 2003 应该安装 CDO。该脚本用于在 Windows XP 和 Server 2003 上运行。此示例使用网络上的 smtp 服务器,但也有其他选项。
Powershell 可能可用于服务器 2003 .. 所以它可能是另一种选择。
================================代码================== ===========
function sendMail ( strFrom, strTo, strSubject, strMessage ) {
尝试{
objMail = Server.CreateObject("CDO.Message");
objConfig = Server.CreateObject("CDO.Configuration");
objFields = objConfig.Fields;
项目(“http://schemas.microsoft.com/cdo/configuration/sendusing”)= 2;
项目(“http://schemas.microsoft.com/cdo/configuration/smtpserver”)=“xxxxsmtp.xxxserver.xxorg”;
项目(“http://schemas.microsoft.com/cdo/configuration/smtpserverport”)= 25;
项目(“http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout”)= 30;
更新();
}
与 (objMail) {
配置=objConfig;
至 = strTo; //"\"用户\" ,"\"另一个用户\" ;"
来自 = strFrom;
主题 = strSubject;
文本正文 = strMessage;
//如果我们需要发送附件
}
//WScript.Echo('qqq');
sendMail( '[电子邮件受保护]', '[电子邮件受保护]', 'test', 'msg');
One simple way would be to use javascript (or VBscript). If you google for "Server.CreateObject("CDO.Message")" you will find more examples.
Put the code below in a file with extension: ".js", for example email.js
To call use "cscript email.js" on the command line. Replace server name and emails with valid values.
Windows 2003 should have CDO installed. The script used to work on windows XP and server 2003. This example uses smtp server over the network but there are other options too.
Powershell is probably available for server 2003 .. so it could be another option.
============================== code ==============================
function sendMail ( strFrom, strTo, strSubject, strMessage ) {
try {
objMail = Server.CreateObject("CDO.Message");
objConfig = Server.CreateObject("CDO.Configuration");
objFields = objConfig.Fields;
Item("http://schemas.microsoft.com/cdo/configuration/sendusing")= 2;
Item("http://schemas.microsoft.com/cdo/configuration/smtpserver")= "xxxxsmtp.xxxserver.xxorg";
Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport")= 25;
Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 30;
Update();
}
with (objMail) {
Configuration = objConfig;
To = strTo; //"\"User\" ,"\"AnotherUser\" ;"
From = strFrom;
Subject = strSubject;
TextBody = strMessage;
//if we need to send an attachement
}
//WScript.Echo('qqq');
sendMail( '[email protected]', '[email protected]' , 'test', 'msg');