我有一台 Windows 2003 R2 服务器,我想从命令行发送电子邮件。此服务器未配置 SMTP 服务。有没有一行代码可以让我发送电子邮件?我目前的具体用例是在触发性能警报时发送电子邮件,但总的来说这很有用。
我希望
foomail -t [email protected] -f [email protected] -m "Alert! the sky is falling"
更新: 我更喜欢不涉及安装第三方软件的解决方案。
答案1
我会尝试布拉特。您可以编写一个 vbscript,但没有内置可执行文件来发送邮件
答案2
您会考虑使用 powershell 而不是 cmd.exe 吗?如果是这样,则内置发送邮件功能:
$SmtpClient = New-Object System.Net.Mail.SmtpClient
$SmtpServer = "your.mail.host.com"
$SmtpClient.host = $SmtpServer
$From = "Me <[email protected]>"
$To = [email protected]
$Title = "Subject"
$Body = "Body Text"
$SmtpClient.Send($From,$To,$Title,$Body)
要制作一行代码,请将以下内容保存到 powershell 脚本文件 (sendmail.ps1):
param(
[string] $From = "[email protected]",
[string] $To = "[email protected]",
[string] $Title = "title",
[string] $Body = "body"
)
$SmtpClient = New-Object System.Net.Mail.SmtpClient
$SmtpServer = "your.mail.host.com"
$SmtpClient.host = $SmtpServer
$SmtpClient.Send($From,$To,$Title,$Body)
(确保将 smtpserver 更改为真实的 smtpserver)
然后你可以使用以下命令调用它:
powershell.exe c:\path\to\sendmail.ps1 "[email protected]" "[email protected]" "title" "body"
答案3
我用过邮件过去取得了巨大的成功。
用法(从网站复制)
C:\>bmail /?
Command Line SMTP Emailer V1.07
Copyright(C) 2002-2004 [email protected]
Usage: bmail [options]
-s SMTP Server Name
-p SMTP Port Number (optional, defaults to 25)
-t To: Address
-f From: Address
-b Text Body of Message (optional)
-h Generate Headers
-a Subject (optional)
-m Filename (optional) Use file as Body of Message
-c Prefix above file with CR/LF to separate body from header
-d Debug (Show all mail server communications)