2013-12-14 128 views
-1

我正在使用批處理程序,當發生崩潰或出現錯誤時,它會生成名爲debug.txt的文本文件。我需要知道是否有一種方法可以使用批處理自動發送此文件到以下電子郵件地址「[email protected]」。 debug.txt與批處理文件位於同一位置。有誰知道我可以使用的代碼。它不能有任何額外的軟件。批量發送電子郵件

+2

如果我是你,我會從這個問題中刪除電子郵件地址,因爲無論如何都不需要它。 – zbr

+1

由於是文字,您可以將其作爲郵件正文發送給他人。例如,'sendmail [options] [email_address] lurker

+2

@Zabri是對的。你不應該在任何公共論壇上發佈你的電子郵件。這是大量獲取垃圾郵件的主要方式。 – lurker

回答

1

我看到你的3個選項,截至目前:

的底線是有沒有在批量沒有內置的方式,但也有第三方的工具,如BLAT等,可以調用從一個批處理文件,但正如你所說,你不想要任何額外的軟件。

2.您可以啓用已安裝的Windows的SMTP服務器。然後運行PowerShell腳本:

$smtpServer = "system.abc.com" 
$smtpFrom = "[email protected]" 
$smtpTo = "[email protected]" 
$messageSubject = "Put your subject here" 

$message = New-Object System.Net.Mail.MailMessage $smtpfrom, $smtpto 
$message.Subject = $messageSubject 
$message.IsBodyHTML = $true 
$message.Body = Get-Content debug.txt 

$smtp = New-Object Net.Mail.SmtpClient($smtpServer) 
$smtp.Send($message) 

可以啓用Windows的安裝SMTP服務器。然後運行一個VBScript:

Const ForReading = 1 
Const ForWriting = 2 
Const ForAppending = 8 
Const FileToBeUsed = "debug.txt" 
Dim objCDO1 
Dim fso, f 
Set fso = CreateObject("Scripting.FileSystemObject") 
Set f = fso.OpenTextFile(FileToBeUsed, ForReading) 
Set objCDO1 = CreateObject("CDO.Message") 
objCDO1.Textbody = f.ReadAll 
f.Close 
objCDO1.TO ="[email protected]" 
objCDO1.From = "[email protected]" 
objCDO1.Subject = "Put your subject here" 
objCDO1.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration /sendusing") = 2 
objCDO1.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration /smtpserver") = "system.abc.com" 
objCDO1.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration /smtpserverport") = 25 
objCDO1.Configuration.Fields.Update  
objCDO1.Send 
Set f = Nothing 
Set fso = Nothing 

正如你所提到的,你使用的是Windows 7旗艦所以無論選擇2和3將您的系統上工作得很好。

0

您可以使用免費的工具,如sendemail.exe http://caspian.dotconf.net/menu/Software/SendEmail/。下載並將sendemail.exe複製到系統路徑。這僅適用於簡單的內部SMTP郵件。除非您的Exchange服務器設置爲發送匿名外部郵件,否則這不能用於發送外部郵件。幾乎所有的Exchange服務器都沒有設置爲執行此操作。

您可以在批處理腳本中使用這個簡單的例程。

CALL:SENDEMAILALERT "From SMTP address" "To SMTP addresses" "Subject" "Message" "File to attach" "smtp.host.com:25" 

:SENDEMAILALERT 
SET SENDEMAILCMD=-f "%~1" 
SET SENDEMAILCMD=%SENDEMAILCMD% -t "%~2" 
SET SENDEMAILCMD=%SENDEMAILCMD% -u "%~3" 
SET SENDEMAILCMD=%SENDEMAILCMD% -m "%~4" 
SET SENDEMAILCMD=%SENDEMAILCMD% -a "%~5" 
SET SENDEMAILCMD=%SENDEMAILCMD% -s "%~6" 
SENDEMAIL %SENDEMAILCMD% >NUL 2>&1 
SET SENDEMAILCMD= 
GOTO:EOF 
+0

正如我在問題中所說的,我需要它不要包含任何額外的軟件。 – 09stephenb