我会使用Blat或 VBscript 来做到这一点。
osql -S <ServerName> -U <User Name> -P <Password> -o Out.txt < mysqlfile.sql
Blat out.txt -to <recipient> -s <subject> -server <ip or hostname of SMTP server:<port>
这是一个创建 VBScript 来执行此操作的批处理文件。
@echo off
setlocal
if exist "out.txt" del "out.txt"
osql -S Server -U user -P password -o Out.txt < mysqlfile.sql
set vbs_=Email.vbs
set skip=
findstr "'%skip%VBS" "%~f0" > "%vbs_%"
cscript //nologo "%vbs_%"
ping -n 3 localhost>nul
if exist "%vbs_%" del "%vbs_%"
goto :eof
Const ForReading = 1, ForWriting = 2 'VBS
sFile="Out.txt" 'VBS
Set oFso = CreateObject("Scripting.FileSystemObject") 'VBS
Set oFile = oFso.OpenTextFile(sFile, ForReading) 'VBS
Set oMail=CreateObject("CDO.Message") 'VBS
sSchema="http://schemas.microsoft.com/cdo/configuration/" 'VBS
with oMail.Configuration.Fields 'VBS
.Item(sSchema & "sendusing")= 2 'VBS
.Item(sSchema & "smtpserver")= "YourServer" 'VBS
.Item(sSchema & "smtpserverport") = 25 'VBS
.Update 'VBS
end with 'VBS
oMail.Subject="SQL Log" 'VBS
oMail.From="email@domain.com" 'VBS
oMail.To="Sendto@someother.com" 'VBS
oMail.TextBody = oFile.ReadAll 'VBS
oMail.Send 'VBS
oFile.Close 'VBS
set oMail=nothing 'VBS
set oFile = Nothing 'VBS