Rohaan Asked: 2017-05-05 22:44:45 +0800 CST2017-05-05 22:44:45 +0800 CST 2017-05-05 22:44:45 +0800 CST 没有配置数据库邮件的 sql 代理作业通知电子邮件 772 有没有办法在不配置数据库邮件的情况下发送 sql 代理作业通知电子邮件? 目前我正在使用数据库邮件,但出于安全考虑,我需要禁用数据库邮件功能。 谢谢。 sql-server-2012 sql-server-agent 2 个回答 Voted Best Answer Scott Hodgin - Retired 2017-05-06T00:43:03+08:002017-05-06T00:43:03+08:00 您可以轻松调用 Powershell 脚本:(更改 FromEmailAddress、ToEmailAddress 和 SmtpClient 信息) $computerName = gc env:computername $emailFrom = $computerName + “<EmailFromAddress>.com” $emailTo = "<EmailToAddress>.com" $subject = "Testing email" $emailBody = "This is an example of sending email via Powershell" $message = New-Object Net.Mail.MailMessage($emailFrom, $emailTo, $subject, $emailbody) $message.Priority = "HIGH" $smtpServer = "<YourSmtpServer>.com" $smtp = New-Object Net.Mail.SmtpClient($smtpServer) $smtp.Send($message) George K 2017-05-05T23:06:02+08:002017-05-05T23:06:02+08:00 如果您不使用数据库邮件,您的选择之一是调用与此类似的 VBScript: Set stream = CreateObject("ADODB.Stream") stream.Open stream.Type = 2 'text stream.Position = 0 stream.Charset = "utf-8" Set Str = WScript.Arguments For I = 0 to Str.Count - 1 res = Str(I) Next Set wshShell = WScript.CreateObject( "WScript.Shell" ) strComputerName = wshShell.ExpandEnvironmentStrings( "%COMPUTERNAME%" ) Set objNet = CreateObject("WScript.NetWork") Const ForReading = 1 Set wshShell = WScript.CreateObject( "WScript.Shell" ) Set objMessage = CreateObject("CDO.Message") objMessage.Subject = "WARNING " & strComputerName & " " & objNet.UserDomain & "." & objNet.UserName objMessage.From = "<FromE-Mail>" objMessage.to="<ToUserE-Mail>" objMessage.TextBody = "The task" & databaseName & " " & " failed on computer " & strComputerName & ". Date and time: " & Now() & vbCrLF & vbCrLf & vbCrlf & vbCrlf & vbCrlf & vbCrlf & "Message: " &res 'This section provides the configuration information for the remote SMTP 'server.Normally you will only change the server name or IP. objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 'Name or IP of Remote SMTP Server objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "YourSMTPServer" 'Server port number(typically 25) objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 'objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 2 objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "domain\user" objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "<password>" objMessage.Configuration.Fields.Update objMessage.Send Const ForWriting = 2 Set objMessage = Nothing stream.Close
您可以轻松调用 Powershell 脚本:(更改 FromEmailAddress、ToEmailAddress 和 SmtpClient 信息)
如果您不使用数据库邮件,您的选择之一是调用与此类似的 VBScript: