Bonjour,
Je souhaiterai ajouter à la fin de mon script de backup automatique un
envoi
de message smtp incluant le fichier log.
J'ai trouver un wscipt (sendmail.vbs) qui fonctionne me permettant
d'envoyer
un message mais pas d'inclure un fichier attaché.
Deux options possibles :
- trouver un script permettant l'ajout d'un fichier attaché,
- ou remplir le corp du message avec les lignes de mon fichier log
N'ayant pas trouver de script avec attachement de fichiers, j'ai envisagé
la
deuxième alternative, mais je n'arrive pas à passer en argument toutes les
lignes de mon fichier log dont un exemple est donné ci-dessous.
Auriez-vous une idée sur la meilleur manière de procéder ?
Merci d'avance
### Fichier log ###
État de la sauvegarde
Opération : sauvegarde
Destination de sauvegarde active : DLT
Nom du média : "SAMEDI-26FÉVRIER2005-12H10_PYRAMIDE"
Sauvegarde (par clichés instantanés) de "System State"
Jeu de sauvegardes n° 1 sur le média n° 1
Description de la sauvegarde : "Backup PYRAMIDE du
SAMEDI-26FÉVRIER2005-12H10"
Nom du média : "SAMEDI-26FÉVRIER2005-12H10_PYRAMIDE"
Type de sauvegarde : Copie
Sauvegarde débutée le 26/02/2005 à 12:11.
Avertissement : Impossible d'ouvrir
"e:windowsSYSVOLdomainDO_NOT_REMOVE_NtFrs_PreInstall_Directory" -
ignoré.
Raison : Le processus ne peut pas accéder au fichier car ce fichier est
utilisé par un autre processus.
Sauvegarde terminée le 26/02/2005 à 12:13.
Répertoires : 299
Fichiers : 2768
Octets : 517 937 833
Durée : 2 minutes et 11 secondes
----------------------
### script sendmail.vbs ###
'* Copyright (C) 2004 Andrew Loree
'* $Id: sendmail.vbs,v 1.5 2004/09/27 13:55:14 andy Exp $
'****************************************************************************
'* sendmail.vbs - Sends an email using the specified command line args
'****************************************************************************
'* This program is free software; you can redistribute it and/or
'* modify it under the terms of the GNU General Public License
'* as published by the Free Software Foundation; either version 2
'* of the License, or (at your option) any later version.
'*
'* This program is distributed in the hope that it will be useful,
'* but WITHOUT ANY WARRANTY; without even the implied warranty of
'* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
'* GNU General Public License for more details.
'*
'* You should have received a copy of the GNU General Public License
'* along with this program; if not, write to the Free Software
'* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
USA.
'****************************************************************************
'* Version History:
'* 1.0 - Initial Release
'****************************************************************************
Option Explicit
Dim sTo, sFrom, sSubject, sMessage, sSMTPServer, nSMTPPort, bVerbose
SetDefaults()
If (ParseCommandLine()) Then
If (bVerbose) Then
WScript.Echo("To: " & sTo)
WScript.Echo("From: " & sFrom)
WScript.Echo("Subject: " & sSubject)
WScript.Echo("Message: " & sMessage)
WScript.Echo("Server: " & sSMTPServer)
WScript.Echo("Port: " & nSMTPPort)
End If
Call SendEmail(sFrom,sTo,sSubject,sMessage,sSMTPServer,nSMTPPort)
Else ' Failed to parse command line options or asked for help
ShowUsage()
End If
' ShowUsage - Shows command line usage
Function ShowUsage()
WScript.Echo("sendmail.vbs - Sends emails using cdo")
WScript.Echo(vbTab & "Usage: sendmail.vbs /TO recipients [/FROM address]
[/SUBJECT subject]")
WScript.Echo(vbTab & " [/MESSAGE message] [/SERVER
server] [/PORT port]")
WScript.Echo(vbTab & " [/VERBOSE]")
WScript.Echo()
WScript.Echo(vbTab & "recipients - Required, comma seperated list of
recipients. Use quotes")
WScript.Echo(vbTab & " if the list might contain spaces")
WScript.Echo(vbTab & "address - Sender from address. If not specified,
current user and")
WScript.Echo(vbTab & " machine name will be used")
WScript.Echo(vbTab & "subject - Subject line")
WScript.Echo(vbTab & "message - Body of the message")
WScript.Echo(vbTab & "server - SMTP server. Default is localhost")
WScript.Echo(vbTab & "port - SMTP Port. Default is 25")
WScript.Echo(vbTab & "verbose - Writes message parameters to standard
out before sending")
End Function
' SetDefaults - Sets initial values
Function SetDefaults()
Dim WshNetwork
sFrom = ""
sSMTPServer = "localhost" ' Default
nSMTPPort = 25
sSubject = "[No Subject]"
sMessage = ""
bVerbose = False
Set WshNetwork = CreateObject("WScript.Network")
If (Len(sFrom) = 0) Then
sFrom = WshNetwork.UserName & "@" & WshNetwork.ComputerName
End If
Set WshNetwork = Nothing
End Function
' ParseCommandLine - Parses command line options into global vars
Function ParseCommandLine()
Dim objArgs, i, sNextArg
Set objArgs = WScript.Arguments
For i = 0 To objArgs.Count - 1
If (i < objArgs.Count - 1) Then
sNextArg = objArgs(i+1)
Else
sNextArg = ""
End If
Select Case (UCase(objArgs(i)))
Case "/TO":
sTo = sNextArg
i = i + 1
Case "/FROM":
sFrom = sNextArg
i = i + 1
Case "/SUBJECT":
sSubject = sNextArg
i = i + 1
Case "/MESSAGE":
sMessage = sNextArg
i = i + 1
Case "/SERVER":
sSMTPServer = sNextArg
i = i + 1
Case "/PORT":
nSMTPPort = sNextArg
i = i + 1
Case "/VERBOSE":
bVerbose = True
Case "/HELP":
ParseCommandLine = False
Exit Function
Case "/H":
ParseCommandLine = False
Exit Function
End Select
Next
' Check for valid arguments
If (Len(sTo) > 0) Then
ParseCommandLine = True
Else
ParseCommandLine = False
End If
End Function
' SendEmail - Sends an email using cdo to the specified
Function SendEmail(sFrom, sTo, sSubject, sMessage, sSMTPServer, nSMTPPort)
Dim oMsg, oConf, oFields, WshNetwork
Const cdoSendUsingPort = 2
Const cdoSendUsingMethod > "http://schemas.microsoft.com/cdo/configuration/sendusing"
Const cdoSMTPServer > "http://schemas.microsoft.com/cdo/configuration/smtpserver"
Const cdoSMTPServerPort > "http://schemas.microsoft.com/cdo/configuration/smtpserverport"
If (Len(sTo) > 0) Then
Set oMsg = CreateObject("CDO.Message")
Set oConf = CreateObject("CDO.Configuration")
Set WshNetwork = CreateObject("WScript.Network")
Set oFields = oConf.Fields
' Set SMTP server configuration
oFields.Item(cdoSendUsingMethod) = cdoSendUsingPort
oFields.Item(cdoSMTPServer) = sSMTPServer
oFields.Item(cdoSMTPServerPort) = nSMTPPort
oFields.Update
'// Set the message properties.
oMsg.Configuration = oConf
oMsg.To = sTo
oMsg.From = sFrom
oMsg.Subject = sSubject
oMsg.Organization = "Sent from " & WshNetwork.ComputerName & " by " &
WshNetwork.UserName
oMsg.TextBody = sMessage
oMsg.Send
Set WshNetwork = Nothing
Set oMsg = Nothing
Set oConf = Nothing
End If
End Function
Bonjour,
Je souhaiterai ajouter à la fin de mon script de backup automatique un
envoi
de message smtp incluant le fichier log.
J'ai trouver un wscipt (sendmail.vbs) qui fonctionne me permettant
d'envoyer
un message mais pas d'inclure un fichier attaché.
Deux options possibles :
- trouver un script permettant l'ajout d'un fichier attaché,
- ou remplir le corp du message avec les lignes de mon fichier log
N'ayant pas trouver de script avec attachement de fichiers, j'ai envisagé
la
deuxième alternative, mais je n'arrive pas à passer en argument toutes les
lignes de mon fichier log dont un exemple est donné ci-dessous.
Auriez-vous une idée sur la meilleur manière de procéder ?
Merci d'avance
### Fichier log ###
État de la sauvegarde
Opération : sauvegarde
Destination de sauvegarde active : DLT
Nom du média : "SAMEDI-26FÉVRIER2005-12H10_PYRAMIDE"
Sauvegarde (par clichés instantanés) de "System State"
Jeu de sauvegardes n° 1 sur le média n° 1
Description de la sauvegarde : "Backup PYRAMIDE du
SAMEDI-26FÉVRIER2005-12H10"
Nom du média : "SAMEDI-26FÉVRIER2005-12H10_PYRAMIDE"
Type de sauvegarde : Copie
Sauvegarde débutée le 26/02/2005 à 12:11.
Avertissement : Impossible d'ouvrir
"e:windowsSYSVOLdomainDO_NOT_REMOVE_NtFrs_PreInstall_Directory" -
ignoré.
Raison : Le processus ne peut pas accéder au fichier car ce fichier est
utilisé par un autre processus.
Sauvegarde terminée le 26/02/2005 à 12:13.
Répertoires : 299
Fichiers : 2768
Octets : 517 937 833
Durée : 2 minutes et 11 secondes
----------------------
### script sendmail.vbs ###
'* Copyright (C) 2004 Andrew Loree
'* $Id: sendmail.vbs,v 1.5 2004/09/27 13:55:14 andy Exp $
'****************************************************************************
'* sendmail.vbs - Sends an email using the specified command line args
'****************************************************************************
'* This program is free software; you can redistribute it and/or
'* modify it under the terms of the GNU General Public License
'* as published by the Free Software Foundation; either version 2
'* of the License, or (at your option) any later version.
'*
'* This program is distributed in the hope that it will be useful,
'* but WITHOUT ANY WARRANTY; without even the implied warranty of
'* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
'* GNU General Public License for more details.
'*
'* You should have received a copy of the GNU General Public License
'* along with this program; if not, write to the Free Software
'* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
USA.
'****************************************************************************
'* Version History:
'* 1.0 - Initial Release
'****************************************************************************
Option Explicit
Dim sTo, sFrom, sSubject, sMessage, sSMTPServer, nSMTPPort, bVerbose
SetDefaults()
If (ParseCommandLine()) Then
If (bVerbose) Then
WScript.Echo("To: " & sTo)
WScript.Echo("From: " & sFrom)
WScript.Echo("Subject: " & sSubject)
WScript.Echo("Message: " & sMessage)
WScript.Echo("Server: " & sSMTPServer)
WScript.Echo("Port: " & nSMTPPort)
End If
Call SendEmail(sFrom,sTo,sSubject,sMessage,sSMTPServer,nSMTPPort)
Else ' Failed to parse command line options or asked for help
ShowUsage()
End If
' ShowUsage - Shows command line usage
Function ShowUsage()
WScript.Echo("sendmail.vbs - Sends emails using cdo")
WScript.Echo(vbTab & "Usage: sendmail.vbs /TO recipients [/FROM address]
[/SUBJECT subject]")
WScript.Echo(vbTab & " [/MESSAGE message] [/SERVER
server] [/PORT port]")
WScript.Echo(vbTab & " [/VERBOSE]")
WScript.Echo()
WScript.Echo(vbTab & "recipients - Required, comma seperated list of
recipients. Use quotes")
WScript.Echo(vbTab & " if the list might contain spaces")
WScript.Echo(vbTab & "address - Sender from address. If not specified,
current user and")
WScript.Echo(vbTab & " machine name will be used")
WScript.Echo(vbTab & "subject - Subject line")
WScript.Echo(vbTab & "message - Body of the message")
WScript.Echo(vbTab & "server - SMTP server. Default is localhost")
WScript.Echo(vbTab & "port - SMTP Port. Default is 25")
WScript.Echo(vbTab & "verbose - Writes message parameters to standard
out before sending")
End Function
' SetDefaults - Sets initial values
Function SetDefaults()
Dim WshNetwork
sFrom = ""
sSMTPServer = "localhost" ' Default
nSMTPPort = 25
sSubject = "[No Subject]"
sMessage = ""
bVerbose = False
Set WshNetwork = CreateObject("WScript.Network")
If (Len(sFrom) = 0) Then
sFrom = WshNetwork.UserName & "@" & WshNetwork.ComputerName
End If
Set WshNetwork = Nothing
End Function
' ParseCommandLine - Parses command line options into global vars
Function ParseCommandLine()
Dim objArgs, i, sNextArg
Set objArgs = WScript.Arguments
For i = 0 To objArgs.Count - 1
If (i < objArgs.Count - 1) Then
sNextArg = objArgs(i+1)
Else
sNextArg = ""
End If
Select Case (UCase(objArgs(i)))
Case "/TO":
sTo = sNextArg
i = i + 1
Case "/FROM":
sFrom = sNextArg
i = i + 1
Case "/SUBJECT":
sSubject = sNextArg
i = i + 1
Case "/MESSAGE":
sMessage = sNextArg
i = i + 1
Case "/SERVER":
sSMTPServer = sNextArg
i = i + 1
Case "/PORT":
nSMTPPort = sNextArg
i = i + 1
Case "/VERBOSE":
bVerbose = True
Case "/HELP":
ParseCommandLine = False
Exit Function
Case "/H":
ParseCommandLine = False
Exit Function
End Select
Next
' Check for valid arguments
If (Len(sTo) > 0) Then
ParseCommandLine = True
Else
ParseCommandLine = False
End If
End Function
' SendEmail - Sends an email using cdo to the specified
Function SendEmail(sFrom, sTo, sSubject, sMessage, sSMTPServer, nSMTPPort)
Dim oMsg, oConf, oFields, WshNetwork
Const cdoSendUsingPort = 2
Const cdoSendUsingMethod > "http://schemas.microsoft.com/cdo/configuration/sendusing"
Const cdoSMTPServer > "http://schemas.microsoft.com/cdo/configuration/smtpserver"
Const cdoSMTPServerPort > "http://schemas.microsoft.com/cdo/configuration/smtpserverport"
If (Len(sTo) > 0) Then
Set oMsg = CreateObject("CDO.Message")
Set oConf = CreateObject("CDO.Configuration")
Set WshNetwork = CreateObject("WScript.Network")
Set oFields = oConf.Fields
' Set SMTP server configuration
oFields.Item(cdoSendUsingMethod) = cdoSendUsingPort
oFields.Item(cdoSMTPServer) = sSMTPServer
oFields.Item(cdoSMTPServerPort) = nSMTPPort
oFields.Update
'// Set the message properties.
oMsg.Configuration = oConf
oMsg.To = sTo
oMsg.From = sFrom
oMsg.Subject = sSubject
oMsg.Organization = "Sent from " & WshNetwork.ComputerName & " by " &
WshNetwork.UserName
oMsg.TextBody = sMessage
oMsg.Send
Set WshNetwork = Nothing
Set oMsg = Nothing
Set oConf = Nothing
End If
End Function
Bonjour,
Je souhaiterai ajouter à la fin de mon script de backup automatique un
envoi
de message smtp incluant le fichier log.
J'ai trouver un wscipt (sendmail.vbs) qui fonctionne me permettant
d'envoyer
un message mais pas d'inclure un fichier attaché.
Deux options possibles :
- trouver un script permettant l'ajout d'un fichier attaché,
- ou remplir le corp du message avec les lignes de mon fichier log
N'ayant pas trouver de script avec attachement de fichiers, j'ai envisagé
la
deuxième alternative, mais je n'arrive pas à passer en argument toutes les
lignes de mon fichier log dont un exemple est donné ci-dessous.
Auriez-vous une idée sur la meilleur manière de procéder ?
Merci d'avance
### Fichier log ###
État de la sauvegarde
Opération : sauvegarde
Destination de sauvegarde active : DLT
Nom du média : "SAMEDI-26FÉVRIER2005-12H10_PYRAMIDE"
Sauvegarde (par clichés instantanés) de "System State"
Jeu de sauvegardes n° 1 sur le média n° 1
Description de la sauvegarde : "Backup PYRAMIDE du
SAMEDI-26FÉVRIER2005-12H10"
Nom du média : "SAMEDI-26FÉVRIER2005-12H10_PYRAMIDE"
Type de sauvegarde : Copie
Sauvegarde débutée le 26/02/2005 à 12:11.
Avertissement : Impossible d'ouvrir
"e:windowsSYSVOLdomainDO_NOT_REMOVE_NtFrs_PreInstall_Directory" -
ignoré.
Raison : Le processus ne peut pas accéder au fichier car ce fichier est
utilisé par un autre processus.
Sauvegarde terminée le 26/02/2005 à 12:13.
Répertoires : 299
Fichiers : 2768
Octets : 517 937 833
Durée : 2 minutes et 11 secondes
----------------------
### script sendmail.vbs ###
'* Copyright (C) 2004 Andrew Loree
'* $Id: sendmail.vbs,v 1.5 2004/09/27 13:55:14 andy Exp $
'****************************************************************************
'* sendmail.vbs - Sends an email using the specified command line args
'****************************************************************************
'* This program is free software; you can redistribute it and/or
'* modify it under the terms of the GNU General Public License
'* as published by the Free Software Foundation; either version 2
'* of the License, or (at your option) any later version.
'*
'* This program is distributed in the hope that it will be useful,
'* but WITHOUT ANY WARRANTY; without even the implied warranty of
'* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
'* GNU General Public License for more details.
'*
'* You should have received a copy of the GNU General Public License
'* along with this program; if not, write to the Free Software
'* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
USA.
'****************************************************************************
'* Version History:
'* 1.0 - Initial Release
'****************************************************************************
Option Explicit
Dim sTo, sFrom, sSubject, sMessage, sSMTPServer, nSMTPPort, bVerbose
SetDefaults()
If (ParseCommandLine()) Then
If (bVerbose) Then
WScript.Echo("To: " & sTo)
WScript.Echo("From: " & sFrom)
WScript.Echo("Subject: " & sSubject)
WScript.Echo("Message: " & sMessage)
WScript.Echo("Server: " & sSMTPServer)
WScript.Echo("Port: " & nSMTPPort)
End If
Call SendEmail(sFrom,sTo,sSubject,sMessage,sSMTPServer,nSMTPPort)
Else ' Failed to parse command line options or asked for help
ShowUsage()
End If
' ShowUsage - Shows command line usage
Function ShowUsage()
WScript.Echo("sendmail.vbs - Sends emails using cdo")
WScript.Echo(vbTab & "Usage: sendmail.vbs /TO recipients [/FROM address]
[/SUBJECT subject]")
WScript.Echo(vbTab & " [/MESSAGE message] [/SERVER
server] [/PORT port]")
WScript.Echo(vbTab & " [/VERBOSE]")
WScript.Echo()
WScript.Echo(vbTab & "recipients - Required, comma seperated list of
recipients. Use quotes")
WScript.Echo(vbTab & " if the list might contain spaces")
WScript.Echo(vbTab & "address - Sender from address. If not specified,
current user and")
WScript.Echo(vbTab & " machine name will be used")
WScript.Echo(vbTab & "subject - Subject line")
WScript.Echo(vbTab & "message - Body of the message")
WScript.Echo(vbTab & "server - SMTP server. Default is localhost")
WScript.Echo(vbTab & "port - SMTP Port. Default is 25")
WScript.Echo(vbTab & "verbose - Writes message parameters to standard
out before sending")
End Function
' SetDefaults - Sets initial values
Function SetDefaults()
Dim WshNetwork
sFrom = ""
sSMTPServer = "localhost" ' Default
nSMTPPort = 25
sSubject = "[No Subject]"
sMessage = ""
bVerbose = False
Set WshNetwork = CreateObject("WScript.Network")
If (Len(sFrom) = 0) Then
sFrom = WshNetwork.UserName & "@" & WshNetwork.ComputerName
End If
Set WshNetwork = Nothing
End Function
' ParseCommandLine - Parses command line options into global vars
Function ParseCommandLine()
Dim objArgs, i, sNextArg
Set objArgs = WScript.Arguments
For i = 0 To objArgs.Count - 1
If (i < objArgs.Count - 1) Then
sNextArg = objArgs(i+1)
Else
sNextArg = ""
End If
Select Case (UCase(objArgs(i)))
Case "/TO":
sTo = sNextArg
i = i + 1
Case "/FROM":
sFrom = sNextArg
i = i + 1
Case "/SUBJECT":
sSubject = sNextArg
i = i + 1
Case "/MESSAGE":
sMessage = sNextArg
i = i + 1
Case "/SERVER":
sSMTPServer = sNextArg
i = i + 1
Case "/PORT":
nSMTPPort = sNextArg
i = i + 1
Case "/VERBOSE":
bVerbose = True
Case "/HELP":
ParseCommandLine = False
Exit Function
Case "/H":
ParseCommandLine = False
Exit Function
End Select
Next
' Check for valid arguments
If (Len(sTo) > 0) Then
ParseCommandLine = True
Else
ParseCommandLine = False
End If
End Function
' SendEmail - Sends an email using cdo to the specified
Function SendEmail(sFrom, sTo, sSubject, sMessage, sSMTPServer, nSMTPPort)
Dim oMsg, oConf, oFields, WshNetwork
Const cdoSendUsingPort = 2
Const cdoSendUsingMethod > "http://schemas.microsoft.com/cdo/configuration/sendusing"
Const cdoSMTPServer > "http://schemas.microsoft.com/cdo/configuration/smtpserver"
Const cdoSMTPServerPort > "http://schemas.microsoft.com/cdo/configuration/smtpserverport"
If (Len(sTo) > 0) Then
Set oMsg = CreateObject("CDO.Message")
Set oConf = CreateObject("CDO.Configuration")
Set WshNetwork = CreateObject("WScript.Network")
Set oFields = oConf.Fields
' Set SMTP server configuration
oFields.Item(cdoSendUsingMethod) = cdoSendUsingPort
oFields.Item(cdoSMTPServer) = sSMTPServer
oFields.Item(cdoSMTPServerPort) = nSMTPPort
oFields.Update
'// Set the message properties.
oMsg.Configuration = oConf
oMsg.To = sTo
oMsg.From = sFrom
oMsg.Subject = sSubject
oMsg.Organization = "Sent from " & WshNetwork.ComputerName & " by " &
WshNetwork.UserName
oMsg.TextBody = sMessage
oMsg.Send
Set WshNetwork = Nothing
Set oMsg = Nothing
Set oConf = Nothing
End If
End Function
Bonjour,
Il y a un exemple de script sur le MSDN :
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/e2k3/e2k3/_cdo_creating_a_message.asp
--
Cordialement,
_________________________________________________________
Jérôme Cornier
Microsoft Services France
"ismans" a écrit dans le message de
news:Bonjour,
Je souhaiterai ajouter à la fin de mon script de backup automatique un
envoi
de message smtp incluant le fichier log.
J'ai trouver un wscipt (sendmail.vbs) qui fonctionne me permettant
d'envoyer
un message mais pas d'inclure un fichier attaché.
Deux options possibles :
- trouver un script permettant l'ajout d'un fichier attaché,
- ou remplir le corp du message avec les lignes de mon fichier log
N'ayant pas trouver de script avec attachement de fichiers, j'ai envisagé
la
deuxième alternative, mais je n'arrive pas à passer en argument toutes
les
lignes de mon fichier log dont un exemple est donné ci-dessous.
Auriez-vous une idée sur la meilleur manière de procéder ?
Merci d'avance
### Fichier log ###
État de la sauvegarde
Opération : sauvegarde
Destination de sauvegarde active : DLT
Nom du média : "SAMEDI-26FÉVRIER2005-12H10_PYRAMIDE"
Sauvegarde (par clichés instantanés) de "System State"
Jeu de sauvegardes n° 1 sur le média n° 1
Description de la sauvegarde : "Backup PYRAMIDE du
SAMEDI-26FÉVRIER2005-12H10"
Nom du média : "SAMEDI-26FÉVRIER2005-12H10_PYRAMIDE"
Type de sauvegarde : Copie
Sauvegarde débutée le 26/02/2005 à 12:11.
Avertissement : Impossible d'ouvrir
"e:windowsSYSVOLdomainDO_NOT_REMOVE_NtFrs_PreInstall_Directory" -
ignoré.
Raison : Le processus ne peut pas accéder au fichier car ce fichier est
utilisé par un autre processus.
Sauvegarde terminée le 26/02/2005 à 12:13.
Répertoires : 299
Fichiers : 2768
Octets : 517 937 833
Durée : 2 minutes et 11 secondes
----------------------
### script sendmail.vbs ###
'* Copyright (C) 2004 Andrew Loree
'* $Id: sendmail.vbs,v 1.5 2004/09/27 13:55:14 andy Exp $
'****************************************************************************
'* sendmail.vbs - Sends an email using the specified command line args
'****************************************************************************
'* This program is free software; you can redistribute it and/or
'* modify it under the terms of the GNU General Public License
'* as published by the Free Software Foundation; either version 2
'* of the License, or (at your option) any later version.
'*
'* This program is distributed in the hope that it will be useful,
'* but WITHOUT ANY WARRANTY; without even the implied warranty of
'* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
'* GNU General Public License for more details.
'*
'* You should have received a copy of the GNU General Public License
'* along with this program; if not, write to the Free Software
'* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
02111-1307,
USA.
'****************************************************************************
'* Version History:
'* 1.0 - Initial Release
'****************************************************************************
Option Explicit
Dim sTo, sFrom, sSubject, sMessage, sSMTPServer, nSMTPPort, bVerbose
SetDefaults()
If (ParseCommandLine()) Then
If (bVerbose) Then
WScript.Echo("To: " & sTo)
WScript.Echo("From: " & sFrom)
WScript.Echo("Subject: " & sSubject)
WScript.Echo("Message: " & sMessage)
WScript.Echo("Server: " & sSMTPServer)
WScript.Echo("Port: " & nSMTPPort)
End If
Call SendEmail(sFrom,sTo,sSubject,sMessage,sSMTPServer,nSMTPPort)
Else ' Failed to parse command line options or asked for help
ShowUsage()
End If
' ShowUsage - Shows command line usage
Function ShowUsage()
WScript.Echo("sendmail.vbs - Sends emails using cdo")
WScript.Echo(vbTab & "Usage: sendmail.vbs /TO recipients [/FROM address]
[/SUBJECT subject]")
WScript.Echo(vbTab & " [/MESSAGE message] [/SERVER
server] [/PORT port]")
WScript.Echo(vbTab & " [/VERBOSE]")
WScript.Echo()
WScript.Echo(vbTab & "recipients - Required, comma seperated list of
recipients. Use quotes")
WScript.Echo(vbTab & " if the list might contain spaces")
WScript.Echo(vbTab & "address - Sender from address. If not
specified,
current user and")
WScript.Echo(vbTab & " machine name will be used")
WScript.Echo(vbTab & "subject - Subject line")
WScript.Echo(vbTab & "message - Body of the message")
WScript.Echo(vbTab & "server - SMTP server. Default is localhost")
WScript.Echo(vbTab & "port - SMTP Port. Default is 25")
WScript.Echo(vbTab & "verbose - Writes message parameters to standard
out before sending")
End Function
' SetDefaults - Sets initial values
Function SetDefaults()
Dim WshNetwork
sFrom = ""
sSMTPServer = "localhost" ' Default
nSMTPPort = 25
sSubject = "[No Subject]"
sMessage = ""
bVerbose = False
Set WshNetwork = CreateObject("WScript.Network")
If (Len(sFrom) = 0) Then
sFrom = WshNetwork.UserName & "@" & WshNetwork.ComputerName
End If
Set WshNetwork = Nothing
End Function
' ParseCommandLine - Parses command line options into global vars
Function ParseCommandLine()
Dim objArgs, i, sNextArg
Set objArgs = WScript.Arguments
For i = 0 To objArgs.Count - 1
If (i < objArgs.Count - 1) Then
sNextArg = objArgs(i+1)
Else
sNextArg = ""
End If
Select Case (UCase(objArgs(i)))
Case "/TO":
sTo = sNextArg
i = i + 1
Case "/FROM":
sFrom = sNextArg
i = i + 1
Case "/SUBJECT":
sSubject = sNextArg
i = i + 1
Case "/MESSAGE":
sMessage = sNextArg
i = i + 1
Case "/SERVER":
sSMTPServer = sNextArg
i = i + 1
Case "/PORT":
nSMTPPort = sNextArg
i = i + 1
Case "/VERBOSE":
bVerbose = True
Case "/HELP":
ParseCommandLine = False
Exit Function
Case "/H":
ParseCommandLine = False
Exit Function
End Select
Next
' Check for valid arguments
If (Len(sTo) > 0) Then
ParseCommandLine = True
Else
ParseCommandLine = False
End If
End Function
' SendEmail - Sends an email using cdo to the specified
Function SendEmail(sFrom, sTo, sSubject, sMessage, sSMTPServer,
nSMTPPort)
Dim oMsg, oConf, oFields, WshNetwork
Const cdoSendUsingPort = 2
Const cdoSendUsingMethod >> "http://schemas.microsoft.com/cdo/configuration/sendusing"
Const cdoSMTPServer >> "http://schemas.microsoft.com/cdo/configuration/smtpserver"
Const cdoSMTPServerPort >> "http://schemas.microsoft.com/cdo/configuration/smtpserverport"
If (Len(sTo) > 0) Then
Set oMsg = CreateObject("CDO.Message")
Set oConf = CreateObject("CDO.Configuration")
Set WshNetwork = CreateObject("WScript.Network")
Set oFields = oConf.Fields
' Set SMTP server configuration
oFields.Item(cdoSendUsingMethod) = cdoSendUsingPort
oFields.Item(cdoSMTPServer) = sSMTPServer
oFields.Item(cdoSMTPServerPort) = nSMTPPort
oFields.Update
'// Set the message properties.
oMsg.Configuration = oConf
oMsg.To = sTo
oMsg.From = sFrom
oMsg.Subject = sSubject
oMsg.Organization = "Sent from " & WshNetwork.ComputerName & " by " &
WshNetwork.UserName
oMsg.TextBody = sMessage
oMsg.Send
Set WshNetwork = Nothing
Set oMsg = Nothing
Set oConf = Nothing
End If
End Function
Bonjour,
Il y a un exemple de script sur le MSDN :
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/e2k3/e2k3/_cdo_creating_a_message.asp
--
Cordialement,
_________________________________________________________
Jérôme Cornier
Microsoft Services France
"ismans" <ismans@discussions.microsoft.com> a écrit dans le message de
news: BB32D5D8-1FE3-47ED-B70F-52CD0602621B@microsoft.com...
Bonjour,
Je souhaiterai ajouter à la fin de mon script de backup automatique un
envoi
de message smtp incluant le fichier log.
J'ai trouver un wscipt (sendmail.vbs) qui fonctionne me permettant
d'envoyer
un message mais pas d'inclure un fichier attaché.
Deux options possibles :
- trouver un script permettant l'ajout d'un fichier attaché,
- ou remplir le corp du message avec les lignes de mon fichier log
N'ayant pas trouver de script avec attachement de fichiers, j'ai envisagé
la
deuxième alternative, mais je n'arrive pas à passer en argument toutes
les
lignes de mon fichier log dont un exemple est donné ci-dessous.
Auriez-vous une idée sur la meilleur manière de procéder ?
Merci d'avance
### Fichier log ###
État de la sauvegarde
Opération : sauvegarde
Destination de sauvegarde active : DLT
Nom du média : "SAMEDI-26FÉVRIER2005-12H10_PYRAMIDE"
Sauvegarde (par clichés instantanés) de "System State"
Jeu de sauvegardes n° 1 sur le média n° 1
Description de la sauvegarde : "Backup PYRAMIDE du
SAMEDI-26FÉVRIER2005-12H10"
Nom du média : "SAMEDI-26FÉVRIER2005-12H10_PYRAMIDE"
Type de sauvegarde : Copie
Sauvegarde débutée le 26/02/2005 à 12:11.
Avertissement : Impossible d'ouvrir
"e:windowsSYSVOLdomainDO_NOT_REMOVE_NtFrs_PreInstall_Directory" -
ignoré.
Raison : Le processus ne peut pas accéder au fichier car ce fichier est
utilisé par un autre processus.
Sauvegarde terminée le 26/02/2005 à 12:13.
Répertoires : 299
Fichiers : 2768
Octets : 517 937 833
Durée : 2 minutes et 11 secondes
----------------------
### script sendmail.vbs ###
'* Copyright (C) 2004 Andrew Loree
'* $Id: sendmail.vbs,v 1.5 2004/09/27 13:55:14 andy Exp $
'****************************************************************************
'* sendmail.vbs - Sends an email using the specified command line args
'****************************************************************************
'* This program is free software; you can redistribute it and/or
'* modify it under the terms of the GNU General Public License
'* as published by the Free Software Foundation; either version 2
'* of the License, or (at your option) any later version.
'*
'* This program is distributed in the hope that it will be useful,
'* but WITHOUT ANY WARRANTY; without even the implied warranty of
'* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
'* GNU General Public License for more details.
'*
'* You should have received a copy of the GNU General Public License
'* along with this program; if not, write to the Free Software
'* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
02111-1307,
USA.
'****************************************************************************
'* Version History:
'* 1.0 - Initial Release
'****************************************************************************
Option Explicit
Dim sTo, sFrom, sSubject, sMessage, sSMTPServer, nSMTPPort, bVerbose
SetDefaults()
If (ParseCommandLine()) Then
If (bVerbose) Then
WScript.Echo("To: " & sTo)
WScript.Echo("From: " & sFrom)
WScript.Echo("Subject: " & sSubject)
WScript.Echo("Message: " & sMessage)
WScript.Echo("Server: " & sSMTPServer)
WScript.Echo("Port: " & nSMTPPort)
End If
Call SendEmail(sFrom,sTo,sSubject,sMessage,sSMTPServer,nSMTPPort)
Else ' Failed to parse command line options or asked for help
ShowUsage()
End If
' ShowUsage - Shows command line usage
Function ShowUsage()
WScript.Echo("sendmail.vbs - Sends emails using cdo")
WScript.Echo(vbTab & "Usage: sendmail.vbs /TO recipients [/FROM address]
[/SUBJECT subject]")
WScript.Echo(vbTab & " [/MESSAGE message] [/SERVER
server] [/PORT port]")
WScript.Echo(vbTab & " [/VERBOSE]")
WScript.Echo()
WScript.Echo(vbTab & "recipients - Required, comma seperated list of
recipients. Use quotes")
WScript.Echo(vbTab & " if the list might contain spaces")
WScript.Echo(vbTab & "address - Sender from address. If not
specified,
current user and")
WScript.Echo(vbTab & " machine name will be used")
WScript.Echo(vbTab & "subject - Subject line")
WScript.Echo(vbTab & "message - Body of the message")
WScript.Echo(vbTab & "server - SMTP server. Default is localhost")
WScript.Echo(vbTab & "port - SMTP Port. Default is 25")
WScript.Echo(vbTab & "verbose - Writes message parameters to standard
out before sending")
End Function
' SetDefaults - Sets initial values
Function SetDefaults()
Dim WshNetwork
sFrom = ""
sSMTPServer = "localhost" ' Default
nSMTPPort = 25
sSubject = "[No Subject]"
sMessage = ""
bVerbose = False
Set WshNetwork = CreateObject("WScript.Network")
If (Len(sFrom) = 0) Then
sFrom = WshNetwork.UserName & "@" & WshNetwork.ComputerName
End If
Set WshNetwork = Nothing
End Function
' ParseCommandLine - Parses command line options into global vars
Function ParseCommandLine()
Dim objArgs, i, sNextArg
Set objArgs = WScript.Arguments
For i = 0 To objArgs.Count - 1
If (i < objArgs.Count - 1) Then
sNextArg = objArgs(i+1)
Else
sNextArg = ""
End If
Select Case (UCase(objArgs(i)))
Case "/TO":
sTo = sNextArg
i = i + 1
Case "/FROM":
sFrom = sNextArg
i = i + 1
Case "/SUBJECT":
sSubject = sNextArg
i = i + 1
Case "/MESSAGE":
sMessage = sNextArg
i = i + 1
Case "/SERVER":
sSMTPServer = sNextArg
i = i + 1
Case "/PORT":
nSMTPPort = sNextArg
i = i + 1
Case "/VERBOSE":
bVerbose = True
Case "/HELP":
ParseCommandLine = False
Exit Function
Case "/H":
ParseCommandLine = False
Exit Function
End Select
Next
' Check for valid arguments
If (Len(sTo) > 0) Then
ParseCommandLine = True
Else
ParseCommandLine = False
End If
End Function
' SendEmail - Sends an email using cdo to the specified
Function SendEmail(sFrom, sTo, sSubject, sMessage, sSMTPServer,
nSMTPPort)
Dim oMsg, oConf, oFields, WshNetwork
Const cdoSendUsingPort = 2
Const cdoSendUsingMethod >> "http://schemas.microsoft.com/cdo/configuration/sendusing"
Const cdoSMTPServer >> "http://schemas.microsoft.com/cdo/configuration/smtpserver"
Const cdoSMTPServerPort >> "http://schemas.microsoft.com/cdo/configuration/smtpserverport"
If (Len(sTo) > 0) Then
Set oMsg = CreateObject("CDO.Message")
Set oConf = CreateObject("CDO.Configuration")
Set WshNetwork = CreateObject("WScript.Network")
Set oFields = oConf.Fields
' Set SMTP server configuration
oFields.Item(cdoSendUsingMethod) = cdoSendUsingPort
oFields.Item(cdoSMTPServer) = sSMTPServer
oFields.Item(cdoSMTPServerPort) = nSMTPPort
oFields.Update
'// Set the message properties.
oMsg.Configuration = oConf
oMsg.To = sTo
oMsg.From = sFrom
oMsg.Subject = sSubject
oMsg.Organization = "Sent from " & WshNetwork.ComputerName & " by " &
WshNetwork.UserName
oMsg.TextBody = sMessage
oMsg.Send
Set WshNetwork = Nothing
Set oMsg = Nothing
Set oConf = Nothing
End If
End Function
Bonjour,
Il y a un exemple de script sur le MSDN :
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/e2k3/e2k3/_cdo_creating_a_message.asp
--
Cordialement,
_________________________________________________________
Jérôme Cornier
Microsoft Services France
"ismans" a écrit dans le message de
news:Bonjour,
Je souhaiterai ajouter à la fin de mon script de backup automatique un
envoi
de message smtp incluant le fichier log.
J'ai trouver un wscipt (sendmail.vbs) qui fonctionne me permettant
d'envoyer
un message mais pas d'inclure un fichier attaché.
Deux options possibles :
- trouver un script permettant l'ajout d'un fichier attaché,
- ou remplir le corp du message avec les lignes de mon fichier log
N'ayant pas trouver de script avec attachement de fichiers, j'ai envisagé
la
deuxième alternative, mais je n'arrive pas à passer en argument toutes
les
lignes de mon fichier log dont un exemple est donné ci-dessous.
Auriez-vous une idée sur la meilleur manière de procéder ?
Merci d'avance
### Fichier log ###
État de la sauvegarde
Opération : sauvegarde
Destination de sauvegarde active : DLT
Nom du média : "SAMEDI-26FÉVRIER2005-12H10_PYRAMIDE"
Sauvegarde (par clichés instantanés) de "System State"
Jeu de sauvegardes n° 1 sur le média n° 1
Description de la sauvegarde : "Backup PYRAMIDE du
SAMEDI-26FÉVRIER2005-12H10"
Nom du média : "SAMEDI-26FÉVRIER2005-12H10_PYRAMIDE"
Type de sauvegarde : Copie
Sauvegarde débutée le 26/02/2005 à 12:11.
Avertissement : Impossible d'ouvrir
"e:windowsSYSVOLdomainDO_NOT_REMOVE_NtFrs_PreInstall_Directory" -
ignoré.
Raison : Le processus ne peut pas accéder au fichier car ce fichier est
utilisé par un autre processus.
Sauvegarde terminée le 26/02/2005 à 12:13.
Répertoires : 299
Fichiers : 2768
Octets : 517 937 833
Durée : 2 minutes et 11 secondes
----------------------
### script sendmail.vbs ###
'* Copyright (C) 2004 Andrew Loree
'* $Id: sendmail.vbs,v 1.5 2004/09/27 13:55:14 andy Exp $
'****************************************************************************
'* sendmail.vbs - Sends an email using the specified command line args
'****************************************************************************
'* This program is free software; you can redistribute it and/or
'* modify it under the terms of the GNU General Public License
'* as published by the Free Software Foundation; either version 2
'* of the License, or (at your option) any later version.
'*
'* This program is distributed in the hope that it will be useful,
'* but WITHOUT ANY WARRANTY; without even the implied warranty of
'* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
'* GNU General Public License for more details.
'*
'* You should have received a copy of the GNU General Public License
'* along with this program; if not, write to the Free Software
'* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
02111-1307,
USA.
'****************************************************************************
'* Version History:
'* 1.0 - Initial Release
'****************************************************************************
Option Explicit
Dim sTo, sFrom, sSubject, sMessage, sSMTPServer, nSMTPPort, bVerbose
SetDefaults()
If (ParseCommandLine()) Then
If (bVerbose) Then
WScript.Echo("To: " & sTo)
WScript.Echo("From: " & sFrom)
WScript.Echo("Subject: " & sSubject)
WScript.Echo("Message: " & sMessage)
WScript.Echo("Server: " & sSMTPServer)
WScript.Echo("Port: " & nSMTPPort)
End If
Call SendEmail(sFrom,sTo,sSubject,sMessage,sSMTPServer,nSMTPPort)
Else ' Failed to parse command line options or asked for help
ShowUsage()
End If
' ShowUsage - Shows command line usage
Function ShowUsage()
WScript.Echo("sendmail.vbs - Sends emails using cdo")
WScript.Echo(vbTab & "Usage: sendmail.vbs /TO recipients [/FROM address]
[/SUBJECT subject]")
WScript.Echo(vbTab & " [/MESSAGE message] [/SERVER
server] [/PORT port]")
WScript.Echo(vbTab & " [/VERBOSE]")
WScript.Echo()
WScript.Echo(vbTab & "recipients - Required, comma seperated list of
recipients. Use quotes")
WScript.Echo(vbTab & " if the list might contain spaces")
WScript.Echo(vbTab & "address - Sender from address. If not
specified,
current user and")
WScript.Echo(vbTab & " machine name will be used")
WScript.Echo(vbTab & "subject - Subject line")
WScript.Echo(vbTab & "message - Body of the message")
WScript.Echo(vbTab & "server - SMTP server. Default is localhost")
WScript.Echo(vbTab & "port - SMTP Port. Default is 25")
WScript.Echo(vbTab & "verbose - Writes message parameters to standard
out before sending")
End Function
' SetDefaults - Sets initial values
Function SetDefaults()
Dim WshNetwork
sFrom = ""
sSMTPServer = "localhost" ' Default
nSMTPPort = 25
sSubject = "[No Subject]"
sMessage = ""
bVerbose = False
Set WshNetwork = CreateObject("WScript.Network")
If (Len(sFrom) = 0) Then
sFrom = WshNetwork.UserName & "@" & WshNetwork.ComputerName
End If
Set WshNetwork = Nothing
End Function
' ParseCommandLine - Parses command line options into global vars
Function ParseCommandLine()
Dim objArgs, i, sNextArg
Set objArgs = WScript.Arguments
For i = 0 To objArgs.Count - 1
If (i < objArgs.Count - 1) Then
sNextArg = objArgs(i+1)
Else
sNextArg = ""
End If
Select Case (UCase(objArgs(i)))
Case "/TO":
sTo = sNextArg
i = i + 1
Case "/FROM":
sFrom = sNextArg
i = i + 1
Case "/SUBJECT":
sSubject = sNextArg
i = i + 1
Case "/MESSAGE":
sMessage = sNextArg
i = i + 1
Case "/SERVER":
sSMTPServer = sNextArg
i = i + 1
Case "/PORT":
nSMTPPort = sNextArg
i = i + 1
Case "/VERBOSE":
bVerbose = True
Case "/HELP":
ParseCommandLine = False
Exit Function
Case "/H":
ParseCommandLine = False
Exit Function
End Select
Next
' Check for valid arguments
If (Len(sTo) > 0) Then
ParseCommandLine = True
Else
ParseCommandLine = False
End If
End Function
' SendEmail - Sends an email using cdo to the specified
Function SendEmail(sFrom, sTo, sSubject, sMessage, sSMTPServer,
nSMTPPort)
Dim oMsg, oConf, oFields, WshNetwork
Const cdoSendUsingPort = 2
Const cdoSendUsingMethod >> "http://schemas.microsoft.com/cdo/configuration/sendusing"
Const cdoSMTPServer >> "http://schemas.microsoft.com/cdo/configuration/smtpserver"
Const cdoSMTPServerPort >> "http://schemas.microsoft.com/cdo/configuration/smtpserverport"
If (Len(sTo) > 0) Then
Set oMsg = CreateObject("CDO.Message")
Set oConf = CreateObject("CDO.Configuration")
Set WshNetwork = CreateObject("WScript.Network")
Set oFields = oConf.Fields
' Set SMTP server configuration
oFields.Item(cdoSendUsingMethod) = cdoSendUsingPort
oFields.Item(cdoSMTPServer) = sSMTPServer
oFields.Item(cdoSMTPServerPort) = nSMTPPort
oFields.Update
'// Set the message properties.
oMsg.Configuration = oConf
oMsg.To = sTo
oMsg.From = sFrom
oMsg.Subject = sSubject
oMsg.Organization = "Sent from " & WshNetwork.ComputerName & " by " &
WshNetwork.UserName
oMsg.TextBody = sMessage
oMsg.Send
Set WshNetwork = Nothing
Set oMsg = Nothing
Set oConf = Nothing
End If
End Function
Re-Bonjour,
Désolé, mon copier/coller ne correspondait pas à la bonne page ...
http://msdn.microsoft.com/library/en-us/e2k3/e2k3/_cdo_adding_attachments.asp
Il y a aussi :
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cdo/html/_olemsg_adding_attachments_to_a_message.asp
--
Cordialement,
_________________________________________________________
Jérôme Cornier
Microsoft Services France
"Jérôme Cornier [MS]" a écrit dans le
message de news:Bonjour,
Il y a un exemple de script sur le MSDN :
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/e2k3/e2k3/_cdo_creating_a_message.asp
--
Cordialement,
_________________________________________________________
Jérôme Cornier
Microsoft Services France
"ismans" a écrit dans le message de
news:Bonjour,
Je souhaiterai ajouter à la fin de mon script de backup automatique un
envoi
de message smtp incluant le fichier log.
J'ai trouver un wscipt (sendmail.vbs) qui fonctionne me permettant
d'envoyer
un message mais pas d'inclure un fichier attaché.
Deux options possibles :
- trouver un script permettant l'ajout d'un fichier attaché,
- ou remplir le corp du message avec les lignes de mon fichier log
N'ayant pas trouver de script avec attachement de fichiers, j'ai envisagé
la
deuxième alternative, mais je n'arrive pas à passer en argument toutes
les
lignes de mon fichier log dont un exemple est donné ci-dessous.
Auriez-vous une idée sur la meilleur manière de procéder ?
Merci d'avance
### Fichier log ###
État de la sauvegarde
Opération : sauvegarde
Destination de sauvegarde active : DLT
Nom du média : "SAMEDI-26FÉVRIER2005-12H10_PYRAMIDE"
Sauvegarde (par clichés instantanés) de "System State"
Jeu de sauvegardes n° 1 sur le média n° 1
Description de la sauvegarde : "Backup PYRAMIDE du
SAMEDI-26FÉVRIER2005-12H10"
Nom du média : "SAMEDI-26FÉVRIER2005-12H10_PYRAMIDE"
Type de sauvegarde : Copie
Sauvegarde débutée le 26/02/2005 à 12:11.
Avertissement : Impossible d'ouvrir
"e:windowsSYSVOLdomainDO_NOT_REMOVE_NtFrs_PreInstall_Directory" -
ignoré.
Raison : Le processus ne peut pas accéder au fichier car ce fichier est
utilisé par un autre processus.
Sauvegarde terminée le 26/02/2005 à 12:13.
Répertoires : 299
Fichiers : 2768
Octets : 517 937 833
Durée : 2 minutes et 11 secondes
----------------------
### script sendmail.vbs ###
'* Copyright (C) 2004 Andrew Loree
'* $Id: sendmail.vbs,v 1.5 2004/09/27 13:55:14 andy Exp $
'****************************************************************************
'* sendmail.vbs - Sends an email using the specified command line args
'****************************************************************************
'* This program is free software; you can redistribute it and/or
'* modify it under the terms of the GNU General Public License
'* as published by the Free Software Foundation; either version 2
'* of the License, or (at your option) any later version.
'*
'* This program is distributed in the hope that it will be useful,
'* but WITHOUT ANY WARRANTY; without even the implied warranty of
'* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
'* GNU General Public License for more details.
'*
'* You should have received a copy of the GNU General Public License
'* along with this program; if not, write to the Free Software
'* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
02111-1307,
USA.
'****************************************************************************
'* Version History:
'* 1.0 - Initial Release
'****************************************************************************
Option Explicit
Dim sTo, sFrom, sSubject, sMessage, sSMTPServer, nSMTPPort, bVerbose
SetDefaults()
If (ParseCommandLine()) Then
If (bVerbose) Then
WScript.Echo("To: " & sTo)
WScript.Echo("From: " & sFrom)
WScript.Echo("Subject: " & sSubject)
WScript.Echo("Message: " & sMessage)
WScript.Echo("Server: " & sSMTPServer)
WScript.Echo("Port: " & nSMTPPort)
End If
Call SendEmail(sFrom,sTo,sSubject,sMessage,sSMTPServer,nSMTPPort)
Else ' Failed to parse command line options or asked for help
ShowUsage()
End If
' ShowUsage - Shows command line usage
Function ShowUsage()
WScript.Echo("sendmail.vbs - Sends emails using cdo")
WScript.Echo(vbTab & "Usage: sendmail.vbs /TO recipients [/FROM address]
[/SUBJECT subject]")
WScript.Echo(vbTab & " [/MESSAGE message] [/SERVER
server] [/PORT port]")
WScript.Echo(vbTab & " [/VERBOSE]")
WScript.Echo()
WScript.Echo(vbTab & "recipients - Required, comma seperated list of
recipients. Use quotes")
WScript.Echo(vbTab & " if the list might contain spaces")
WScript.Echo(vbTab & "address - Sender from address. If not
specified,
current user and")
WScript.Echo(vbTab & " machine name will be used")
WScript.Echo(vbTab & "subject - Subject line")
WScript.Echo(vbTab & "message - Body of the message")
WScript.Echo(vbTab & "server - SMTP server. Default is localhost")
WScript.Echo(vbTab & "port - SMTP Port. Default is 25")
WScript.Echo(vbTab & "verbose - Writes message parameters to standard
out before sending")
End Function
' SetDefaults - Sets initial values
Function SetDefaults()
Dim WshNetwork
sFrom = ""
sSMTPServer = "localhost" ' Default
nSMTPPort = 25
sSubject = "[No Subject]"
sMessage = ""
bVerbose = False
Set WshNetwork = CreateObject("WScript.Network")
If (Len(sFrom) = 0) Then
sFrom = WshNetwork.UserName & "@" & WshNetwork.ComputerName
End If
Set WshNetwork = Nothing
End Function
' ParseCommandLine - Parses command line options into global vars
Function ParseCommandLine()
Dim objArgs, i, sNextArg
Set objArgs = WScript.Arguments
For i = 0 To objArgs.Count - 1
If (i < objArgs.Count - 1) Then
sNextArg = objArgs(i+1)
Else
sNextArg = ""
End If
Select Case (UCase(objArgs(i)))
Case "/TO":
sTo = sNextArg
i = i + 1
Case "/FROM":
sFrom = sNextArg
i = i + 1
Case "/SUBJECT":
sSubject = sNextArg
i = i + 1
Case "/MESSAGE":
sMessage = sNextArg
i = i + 1
Case "/SERVER":
sSMTPServer = sNextArg
i = i + 1
Case "/PORT":
nSMTPPort = sNextArg
i = i + 1
Case "/VERBOSE":
bVerbose = True
Case "/HELP":
ParseCommandLine = False
Exit Function
Case "/H":
ParseCommandLine = False
Exit Function
End Select
Next
' Check for valid arguments
If (Len(sTo) > 0) Then
ParseCommandLine = True
Else
ParseCommandLine = False
End If
End Function
' SendEmail - Sends an email using cdo to the specified
Function SendEmail(sFrom, sTo, sSubject, sMessage, sSMTPServer,
nSMTPPort)
Dim oMsg, oConf, oFields, WshNetwork
Const cdoSendUsingPort = 2
Const cdoSendUsingMethod > >> "http://schemas.microsoft.com/cdo/configuration/sendusing"
Const cdoSMTPServer > >> "http://schemas.microsoft.com/cdo/configuration/smtpserver"
Const cdoSMTPServerPort > >> "http://schemas.microsoft.com/cdo/configuration/smtpserverport"
If (Len(sTo) > 0) Then
Set oMsg = CreateObject("CDO.Message")
Set oConf = CreateObject("CDO.Configuration")
Set WshNetwork = CreateObject("WScript.Network")
Set oFields = oConf.Fields
' Set SMTP server configuration
oFields.Item(cdoSendUsingMethod) = cdoSendUsingPort
oFields.Item(cdoSMTPServer) = sSMTPServer
oFields.Item(cdoSMTPServerPort) = nSMTPPort
oFields.Update
'// Set the message properties.
oMsg.Configuration = oConf
oMsg.To = sTo
oMsg.From = sFrom
oMsg.Subject = sSubject
oMsg.Organization = "Sent from " & WshNetwork.ComputerName & " by " &
WshNetwork.UserName
oMsg.TextBody = sMessage
oMsg.Send
Set WshNetwork = Nothing
Set oMsg = Nothing
Set oConf = Nothing
End If
End Function
Re-Bonjour,
Désolé, mon copier/coller ne correspondait pas à la bonne page ...
http://msdn.microsoft.com/library/en-us/e2k3/e2k3/_cdo_adding_attachments.asp
Il y a aussi :
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cdo/html/_olemsg_adding_attachments_to_a_message.asp
--
Cordialement,
_________________________________________________________
Jérôme Cornier
Microsoft Services France
"Jérôme Cornier [MS]" <jcornier@online.microsoft.com> a écrit dans le
message de news: uQrb2ANHFHA.720@TK2MSFTNGP10.phx.gbl...
Bonjour,
Il y a un exemple de script sur le MSDN :
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/e2k3/e2k3/_cdo_creating_a_message.asp
--
Cordialement,
_________________________________________________________
Jérôme Cornier
Microsoft Services France
"ismans" <ismans@discussions.microsoft.com> a écrit dans le message de
news: BB32D5D8-1FE3-47ED-B70F-52CD0602621B@microsoft.com...
Bonjour,
Je souhaiterai ajouter à la fin de mon script de backup automatique un
envoi
de message smtp incluant le fichier log.
J'ai trouver un wscipt (sendmail.vbs) qui fonctionne me permettant
d'envoyer
un message mais pas d'inclure un fichier attaché.
Deux options possibles :
- trouver un script permettant l'ajout d'un fichier attaché,
- ou remplir le corp du message avec les lignes de mon fichier log
N'ayant pas trouver de script avec attachement de fichiers, j'ai envisagé
la
deuxième alternative, mais je n'arrive pas à passer en argument toutes
les
lignes de mon fichier log dont un exemple est donné ci-dessous.
Auriez-vous une idée sur la meilleur manière de procéder ?
Merci d'avance
### Fichier log ###
État de la sauvegarde
Opération : sauvegarde
Destination de sauvegarde active : DLT
Nom du média : "SAMEDI-26FÉVRIER2005-12H10_PYRAMIDE"
Sauvegarde (par clichés instantanés) de "System State"
Jeu de sauvegardes n° 1 sur le média n° 1
Description de la sauvegarde : "Backup PYRAMIDE du
SAMEDI-26FÉVRIER2005-12H10"
Nom du média : "SAMEDI-26FÉVRIER2005-12H10_PYRAMIDE"
Type de sauvegarde : Copie
Sauvegarde débutée le 26/02/2005 à 12:11.
Avertissement : Impossible d'ouvrir
"e:windowsSYSVOLdomainDO_NOT_REMOVE_NtFrs_PreInstall_Directory" -
ignoré.
Raison : Le processus ne peut pas accéder au fichier car ce fichier est
utilisé par un autre processus.
Sauvegarde terminée le 26/02/2005 à 12:13.
Répertoires : 299
Fichiers : 2768
Octets : 517 937 833
Durée : 2 minutes et 11 secondes
----------------------
### script sendmail.vbs ###
'* Copyright (C) 2004 Andrew Loree
'* $Id: sendmail.vbs,v 1.5 2004/09/27 13:55:14 andy Exp $
'****************************************************************************
'* sendmail.vbs - Sends an email using the specified command line args
'****************************************************************************
'* This program is free software; you can redistribute it and/or
'* modify it under the terms of the GNU General Public License
'* as published by the Free Software Foundation; either version 2
'* of the License, or (at your option) any later version.
'*
'* This program is distributed in the hope that it will be useful,
'* but WITHOUT ANY WARRANTY; without even the implied warranty of
'* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
'* GNU General Public License for more details.
'*
'* You should have received a copy of the GNU General Public License
'* along with this program; if not, write to the Free Software
'* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
02111-1307,
USA.
'****************************************************************************
'* Version History:
'* 1.0 - Initial Release
'****************************************************************************
Option Explicit
Dim sTo, sFrom, sSubject, sMessage, sSMTPServer, nSMTPPort, bVerbose
SetDefaults()
If (ParseCommandLine()) Then
If (bVerbose) Then
WScript.Echo("To: " & sTo)
WScript.Echo("From: " & sFrom)
WScript.Echo("Subject: " & sSubject)
WScript.Echo("Message: " & sMessage)
WScript.Echo("Server: " & sSMTPServer)
WScript.Echo("Port: " & nSMTPPort)
End If
Call SendEmail(sFrom,sTo,sSubject,sMessage,sSMTPServer,nSMTPPort)
Else ' Failed to parse command line options or asked for help
ShowUsage()
End If
' ShowUsage - Shows command line usage
Function ShowUsage()
WScript.Echo("sendmail.vbs - Sends emails using cdo")
WScript.Echo(vbTab & "Usage: sendmail.vbs /TO recipients [/FROM address]
[/SUBJECT subject]")
WScript.Echo(vbTab & " [/MESSAGE message] [/SERVER
server] [/PORT port]")
WScript.Echo(vbTab & " [/VERBOSE]")
WScript.Echo()
WScript.Echo(vbTab & "recipients - Required, comma seperated list of
recipients. Use quotes")
WScript.Echo(vbTab & " if the list might contain spaces")
WScript.Echo(vbTab & "address - Sender from address. If not
specified,
current user and")
WScript.Echo(vbTab & " machine name will be used")
WScript.Echo(vbTab & "subject - Subject line")
WScript.Echo(vbTab & "message - Body of the message")
WScript.Echo(vbTab & "server - SMTP server. Default is localhost")
WScript.Echo(vbTab & "port - SMTP Port. Default is 25")
WScript.Echo(vbTab & "verbose - Writes message parameters to standard
out before sending")
End Function
' SetDefaults - Sets initial values
Function SetDefaults()
Dim WshNetwork
sFrom = ""
sSMTPServer = "localhost" ' Default
nSMTPPort = 25
sSubject = "[No Subject]"
sMessage = ""
bVerbose = False
Set WshNetwork = CreateObject("WScript.Network")
If (Len(sFrom) = 0) Then
sFrom = WshNetwork.UserName & "@" & WshNetwork.ComputerName
End If
Set WshNetwork = Nothing
End Function
' ParseCommandLine - Parses command line options into global vars
Function ParseCommandLine()
Dim objArgs, i, sNextArg
Set objArgs = WScript.Arguments
For i = 0 To objArgs.Count - 1
If (i < objArgs.Count - 1) Then
sNextArg = objArgs(i+1)
Else
sNextArg = ""
End If
Select Case (UCase(objArgs(i)))
Case "/TO":
sTo = sNextArg
i = i + 1
Case "/FROM":
sFrom = sNextArg
i = i + 1
Case "/SUBJECT":
sSubject = sNextArg
i = i + 1
Case "/MESSAGE":
sMessage = sNextArg
i = i + 1
Case "/SERVER":
sSMTPServer = sNextArg
i = i + 1
Case "/PORT":
nSMTPPort = sNextArg
i = i + 1
Case "/VERBOSE":
bVerbose = True
Case "/HELP":
ParseCommandLine = False
Exit Function
Case "/H":
ParseCommandLine = False
Exit Function
End Select
Next
' Check for valid arguments
If (Len(sTo) > 0) Then
ParseCommandLine = True
Else
ParseCommandLine = False
End If
End Function
' SendEmail - Sends an email using cdo to the specified
Function SendEmail(sFrom, sTo, sSubject, sMessage, sSMTPServer,
nSMTPPort)
Dim oMsg, oConf, oFields, WshNetwork
Const cdoSendUsingPort = 2
Const cdoSendUsingMethod > >> "http://schemas.microsoft.com/cdo/configuration/sendusing"
Const cdoSMTPServer > >> "http://schemas.microsoft.com/cdo/configuration/smtpserver"
Const cdoSMTPServerPort > >> "http://schemas.microsoft.com/cdo/configuration/smtpserverport"
If (Len(sTo) > 0) Then
Set oMsg = CreateObject("CDO.Message")
Set oConf = CreateObject("CDO.Configuration")
Set WshNetwork = CreateObject("WScript.Network")
Set oFields = oConf.Fields
' Set SMTP server configuration
oFields.Item(cdoSendUsingMethod) = cdoSendUsingPort
oFields.Item(cdoSMTPServer) = sSMTPServer
oFields.Item(cdoSMTPServerPort) = nSMTPPort
oFields.Update
'// Set the message properties.
oMsg.Configuration = oConf
oMsg.To = sTo
oMsg.From = sFrom
oMsg.Subject = sSubject
oMsg.Organization = "Sent from " & WshNetwork.ComputerName & " by " &
WshNetwork.UserName
oMsg.TextBody = sMessage
oMsg.Send
Set WshNetwork = Nothing
Set oMsg = Nothing
Set oConf = Nothing
End If
End Function
Re-Bonjour,
Désolé, mon copier/coller ne correspondait pas à la bonne page ...
http://msdn.microsoft.com/library/en-us/e2k3/e2k3/_cdo_adding_attachments.asp
Il y a aussi :
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cdo/html/_olemsg_adding_attachments_to_a_message.asp
--
Cordialement,
_________________________________________________________
Jérôme Cornier
Microsoft Services France
"Jérôme Cornier [MS]" a écrit dans le
message de news:Bonjour,
Il y a un exemple de script sur le MSDN :
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/e2k3/e2k3/_cdo_creating_a_message.asp
--
Cordialement,
_________________________________________________________
Jérôme Cornier
Microsoft Services France
"ismans" a écrit dans le message de
news:Bonjour,
Je souhaiterai ajouter à la fin de mon script de backup automatique un
envoi
de message smtp incluant le fichier log.
J'ai trouver un wscipt (sendmail.vbs) qui fonctionne me permettant
d'envoyer
un message mais pas d'inclure un fichier attaché.
Deux options possibles :
- trouver un script permettant l'ajout d'un fichier attaché,
- ou remplir le corp du message avec les lignes de mon fichier log
N'ayant pas trouver de script avec attachement de fichiers, j'ai envisagé
la
deuxième alternative, mais je n'arrive pas à passer en argument toutes
les
lignes de mon fichier log dont un exemple est donné ci-dessous.
Auriez-vous une idée sur la meilleur manière de procéder ?
Merci d'avance
### Fichier log ###
État de la sauvegarde
Opération : sauvegarde
Destination de sauvegarde active : DLT
Nom du média : "SAMEDI-26FÉVRIER2005-12H10_PYRAMIDE"
Sauvegarde (par clichés instantanés) de "System State"
Jeu de sauvegardes n° 1 sur le média n° 1
Description de la sauvegarde : "Backup PYRAMIDE du
SAMEDI-26FÉVRIER2005-12H10"
Nom du média : "SAMEDI-26FÉVRIER2005-12H10_PYRAMIDE"
Type de sauvegarde : Copie
Sauvegarde débutée le 26/02/2005 à 12:11.
Avertissement : Impossible d'ouvrir
"e:windowsSYSVOLdomainDO_NOT_REMOVE_NtFrs_PreInstall_Directory" -
ignoré.
Raison : Le processus ne peut pas accéder au fichier car ce fichier est
utilisé par un autre processus.
Sauvegarde terminée le 26/02/2005 à 12:13.
Répertoires : 299
Fichiers : 2768
Octets : 517 937 833
Durée : 2 minutes et 11 secondes
----------------------
### script sendmail.vbs ###
'* Copyright (C) 2004 Andrew Loree
'* $Id: sendmail.vbs,v 1.5 2004/09/27 13:55:14 andy Exp $
'****************************************************************************
'* sendmail.vbs - Sends an email using the specified command line args
'****************************************************************************
'* This program is free software; you can redistribute it and/or
'* modify it under the terms of the GNU General Public License
'* as published by the Free Software Foundation; either version 2
'* of the License, or (at your option) any later version.
'*
'* This program is distributed in the hope that it will be useful,
'* but WITHOUT ANY WARRANTY; without even the implied warranty of
'* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
'* GNU General Public License for more details.
'*
'* You should have received a copy of the GNU General Public License
'* along with this program; if not, write to the Free Software
'* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
02111-1307,
USA.
'****************************************************************************
'* Version History:
'* 1.0 - Initial Release
'****************************************************************************
Option Explicit
Dim sTo, sFrom, sSubject, sMessage, sSMTPServer, nSMTPPort, bVerbose
SetDefaults()
If (ParseCommandLine()) Then
If (bVerbose) Then
WScript.Echo("To: " & sTo)
WScript.Echo("From: " & sFrom)
WScript.Echo("Subject: " & sSubject)
WScript.Echo("Message: " & sMessage)
WScript.Echo("Server: " & sSMTPServer)
WScript.Echo("Port: " & nSMTPPort)
End If
Call SendEmail(sFrom,sTo,sSubject,sMessage,sSMTPServer,nSMTPPort)
Else ' Failed to parse command line options or asked for help
ShowUsage()
End If
' ShowUsage - Shows command line usage
Function ShowUsage()
WScript.Echo("sendmail.vbs - Sends emails using cdo")
WScript.Echo(vbTab & "Usage: sendmail.vbs /TO recipients [/FROM address]
[/SUBJECT subject]")
WScript.Echo(vbTab & " [/MESSAGE message] [/SERVER
server] [/PORT port]")
WScript.Echo(vbTab & " [/VERBOSE]")
WScript.Echo()
WScript.Echo(vbTab & "recipients - Required, comma seperated list of
recipients. Use quotes")
WScript.Echo(vbTab & " if the list might contain spaces")
WScript.Echo(vbTab & "address - Sender from address. If not
specified,
current user and")
WScript.Echo(vbTab & " machine name will be used")
WScript.Echo(vbTab & "subject - Subject line")
WScript.Echo(vbTab & "message - Body of the message")
WScript.Echo(vbTab & "server - SMTP server. Default is localhost")
WScript.Echo(vbTab & "port - SMTP Port. Default is 25")
WScript.Echo(vbTab & "verbose - Writes message parameters to standard
out before sending")
End Function
' SetDefaults - Sets initial values
Function SetDefaults()
Dim WshNetwork
sFrom = ""
sSMTPServer = "localhost" ' Default
nSMTPPort = 25
sSubject = "[No Subject]"
sMessage = ""
bVerbose = False
Set WshNetwork = CreateObject("WScript.Network")
If (Len(sFrom) = 0) Then
sFrom = WshNetwork.UserName & "@" & WshNetwork.ComputerName
End If
Set WshNetwork = Nothing
End Function
' ParseCommandLine - Parses command line options into global vars
Function ParseCommandLine()
Dim objArgs, i, sNextArg
Set objArgs = WScript.Arguments
For i = 0 To objArgs.Count - 1
If (i < objArgs.Count - 1) Then
sNextArg = objArgs(i+1)
Else
sNextArg = ""
End If
Select Case (UCase(objArgs(i)))
Case "/TO":
sTo = sNextArg
i = i + 1
Case "/FROM":
sFrom = sNextArg
i = i + 1
Case "/SUBJECT":
sSubject = sNextArg
i = i + 1
Case "/MESSAGE":
sMessage = sNextArg
i = i + 1
Case "/SERVER":
sSMTPServer = sNextArg
i = i + 1
Case "/PORT":
nSMTPPort = sNextArg
i = i + 1
Case "/VERBOSE":
bVerbose = True
Case "/HELP":
ParseCommandLine = False
Exit Function
Case "/H":
ParseCommandLine = False
Exit Function
End Select
Next
' Check for valid arguments
If (Len(sTo) > 0) Then
ParseCommandLine = True
Else
ParseCommandLine = False
End If
End Function
' SendEmail - Sends an email using cdo to the specified
Function SendEmail(sFrom, sTo, sSubject, sMessage, sSMTPServer,
nSMTPPort)
Dim oMsg, oConf, oFields, WshNetwork
Const cdoSendUsingPort = 2
Const cdoSendUsingMethod > >> "http://schemas.microsoft.com/cdo/configuration/sendusing"
Const cdoSMTPServer > >> "http://schemas.microsoft.com/cdo/configuration/smtpserver"
Const cdoSMTPServerPort > >> "http://schemas.microsoft.com/cdo/configuration/smtpserverport"
If (Len(sTo) > 0) Then
Set oMsg = CreateObject("CDO.Message")
Set oConf = CreateObject("CDO.Configuration")
Set WshNetwork = CreateObject("WScript.Network")
Set oFields = oConf.Fields
' Set SMTP server configuration
oFields.Item(cdoSendUsingMethod) = cdoSendUsingPort
oFields.Item(cdoSMTPServer) = sSMTPServer
oFields.Item(cdoSMTPServerPort) = nSMTPPort
oFields.Update
'// Set the message properties.
oMsg.Configuration = oConf
oMsg.To = sTo
oMsg.From = sFrom
oMsg.Subject = sSubject
oMsg.Organization = "Sent from " & WshNetwork.ComputerName & " by " &
WshNetwork.UserName
oMsg.TextBody = sMessage
oMsg.Send
Set WshNetwork = Nothing
Set oMsg = Nothing
Set oConf = Nothing
End If
End Function