使用Windows 2003 R2从命令行发送电子邮件最简单的方法

我有一个Windows 2003 R2服务器,我想从命令行发送一封电子邮件。 此服务器没有configurationSMTP服务。 是否有一个class轮,让我发送电子邮件? 目前我的具体使用案例是在性能提醒被触发时发送电子邮件,但一般情况下它会有用。

我希望有类似的东西

foomail -t [email protected] -f [email protected] -m "Alert! the sky is falling" 

更新:我更喜欢不涉及安装第三方软件的解决scheme。

我会尝试嘘 。 你可以写一个VBScript,但没有内置的可执行文件来发送邮件

你会考虑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) 

要制作一个class轮,请将以下内容保存到一个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更改为您的真实身份)

那么你可以使用它来调用它:

 powershell.exe c:\path\to\sendmail.ps1 "[email protected]" "[email protected]" "title" "body" 

过去我使用bmail取得了巨大的成功。

用法(从网站复制)

 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) 

尝试免费的邮件提醒简单的邮件: https : //sourceforge.net/projects/mail-alert/

它支持像Gmail这样的SSL / TLS邮件服务器及其“易于configuration”。

多一个命令行邮件程序:

  • mailsend

它也支持SSL。

这是一个非常简单的解决scheme。 在Windows SBS 2011上适用于我。以下是我用来发送关于服务器硬盘状态的每日报告:

 blat status.txt -to [email protected] -subject "HP Server Status" -server smtp.server.com -f [email protected] -u [email protected] -pw mypassword 

传说:

status.txt – 电子邮件的正文

-f – “from”,发件人的地址

-u – SMTPauthentication的用户(我们的ISP的SMTP服务器需要authentication)

-pw – SMTPauthentication的密码