Windows编程-发送电子邮件脚本

发布于 2024-11-26 23:10:53 字数 292 浏览 2 评论 0原文

正在寻找一个可以在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦在深巷 2024-12-03 23:10:53

一种简单的方法是使用 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;

    with (objFields) {          

项目(“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;
//如果我们需要发送附件

    //AddAttachment("D:\\test.doc");
        Send();
    }           
}
catch(e) {
WScript.Echo(e.message);
    return false;
}   
delete objFields;
delete objConfig;
delete objMail;   
return true;

}

//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;

    with (objFields) {          

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

    //AddAttachment("D:\\test.doc");
        Send();
    }           
}
catch(e) {
WScript.Echo(e.message);
    return false;
}   
delete objFields;
delete objConfig;
delete objMail;   
return true;

}

//WScript.Echo('qqq');

sendMail( '[email protected]', '[email protected]' , 'test', 'msg');

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文