Pet*_*ter 11 email windows-server-2003 command-line-interface
我有一台 Windows 2003 R2 服务器,我想从命令行发送电子邮件。此服务器未配置 SMTP 服务。有没有可以让我发送电子邮件的班轮?我目前的具体用例是在触发性能警报时发送电子邮件,但它通常很有用。
我希望有类似的东西
foomail -t peter@example.org -f blah@example.org -m "Alert! the sky is falling"
Run Code Online (Sandbox Code Playgroud)
更新: 我更喜欢不涉及安装 3rd 方软件的解决方案。
Mat*_*ttB 14
您会考虑使用 powershell 而不是 cmd.exe 吗?如果是这样,发送邮件是内置的:
$SmtpClient = New-Object System.Net.Mail.SmtpClient
$SmtpServer = "your.mail.host.com"
$SmtpClient.host = $SmtpServer
$From = "Me <User@example.com>"
$To = User2@example.com
$Title = "Subject"
$Body = "Body Text"
$SmtpClient.Send($From,$To,$Title,$Body)
Run Code Online (Sandbox Code Playgroud)
要制作单衬,请将以下内容保存到 powershell 脚本文件 (sendmail.ps1):
param(
[string] $From = "from@example.com",
[string] $To = "to@example.com",
[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)
Run Code Online (Sandbox Code Playgroud)
(确保将 smtpserver 更改为您的真实服务器)
然后你可以使用以下方法调用它:
powershell.exe c:\path\to\sendmail.ps1 "from@example.com" "to@example.com" "title" "body"
Run Code Online (Sandbox Code Playgroud)
我过去使用bmail取得了巨大成功。
用法(从网站复制)
C:\>bmail /?
Command Line SMTP Emailer V1.07
Copyright(C) 2002-2004 Craig.Peacock@beyondlogic.org
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)
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
48823 次 |
最近记录: |