Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

Envoi de mail en fin de procedure de backup

6 réponses
Avatar
ismans
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:\windows\SYSVOL\domain\DO_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

6 réponses

Avatar
F. Dunoyer [MVP]
ismans a formulé la demande :
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

Pour ce genre de chose j'utilisais BLAT

Envoie de fichier via serveur SMTP en ligne de commande
pour le trouvers voir la boite a outils du site www.ntfaqfr.com

--
François Dunoyer [MVP Windows Server - Windows NT Server]
Quelques textes qui m'ont séduit : http://fdunoyer.free.fr/textes.htm
Site perso : http://www.fdunoyer.net

Avatar
Prosper Youp La Boum \(SDI\)
Bonsoir,
Personnellement j'utilise GBmailer, là :
http://www.brothersoft.com/soft/gbma112.zip
L'avantage on peut lui donner un nom de fichier qui sera le corps du
message.

A+


"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




Avatar
ismans
Merci,

ce petit outil (GBmailer) qui fonctionne presque à merveille... Il n'accepte
pas en entrée mon fichier log ntbakup : problème d'accentuation. J'ai dû
ajouter dans mon script la commande :
type backup.log > backup1.log et c'est ce fichier backup1.log que je passe
en arguement du prog gbmail.
Le texte pert en lisibilité mais au moins passe...
Merci encore pour votre aide.

Pour info, j'ai poussé un peu mes recherches en VB et j'ai trouvé ceci qui
fonctionne très bien à l'adresse suivante :
http://cwashington.netreach.net/depo/view.asp?Indexs5&ScriptType=vbscript

'//////////////////////
'//
'// Send SMTP Mail messsage via VBScript.
'// 12/09/02
'//
'// Written by: Nathan Strimling
'//
'// Description: This script will send an email message via smtp without
'// the need for a smtp application such as blat.exe, etc.
'//
'//
'// Intended Usage: SMTP messaging.
'//
'//
'// Dependencies:
'//
'//
'// Caution & Other Notes: This has only been tested under Win2k. Items
'// contained within <>'s are to be replaced with
'// your own information.
'//
'//
'// Modification History:
'//
'// Developer Date Description of Changes
'// ------ ---- ------------
'//
'//
'//////////////////////

'// Set the visual basic constants as they do not exist within VBScript.
' Do not set your smtp server information here.
Const cdoSendUsingMethod =
"http://schemas.microsoft.com/cdo/configuration/sendusing", _
cdoSendUsingPort = 2, _
cdoSMTPServer = "http://schemas.microsoft.com/cdo/configuration/smtpserver"

'// Create the CDO connections.
Dim iMsg, iConf, Flds
Set iMsg = CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")
Set Flds = iConf.Fields

'// SMTP server configuration.
With Flds
.Item(cdoSendUsingMethod) = cdoSendUsingPort

'// Set the SMTP server address here.
.Item(cdoSMTPServer) = "192.168.0.12"
.Update
End With

'// Set the message properties.
With iMsg
Set .Configuration = iConf
.To = ""
.From = ""
.Subject = "Fin Backup"
.TextBody = "Voir fichier attaché"
End With

'// An attachment can be included.
iMsg.AddAttachment "C:tempbackup.log"

'// Send the message.
iMsg.Send ' send the message.

A+
ismans



Bonsoir,
Personnellement j'utilise GBmailer, là :
http://www.brothersoft.com/soft/gbma112.zip
L'avantage on peut lui donner un nom de fichier qui sera le corps du
message.

A+


"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









Avatar
ismans
Merci.

Voici un lien sur BLAT qui fonctionne.
http://www.blat.net/194/

Pour info, j'ai poussé un peu mes recherches en VB et j'ai trouvé ceci qui
fonctionne très bien à l'adresse suivante :
http://cwashington.netreach.net/depo/view.asp?Indexs5&ScriptType=vbscript

Cordialement
ismans


ismans a formulé la demande :
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

Pour ce genre de chose j'utilisais BLAT

Envoie de fichier via serveur SMTP en ligne de commande
pour le trouvers voir la boite a outils du site www.ntfaqfr.com

--
François Dunoyer [MVP Windows Server - Windows NT Server]
Quelques textes qui m'ont séduit : http://fdunoyer.free.fr/textes.htm
Site perso : http://www.fdunoyer.net





Avatar
Prosper Youp La Boum \(SDI\)
Bonsoir,
Merci pour le retour
A+

"ismans" a écrit dans le message de
news:
Merci,

ce petit outil (GBmailer) qui fonctionne presque à merveille... Il
n'accepte

pas en entrée mon fichier log ntbakup : problème d'accentuation. J'ai dû
ajouter dans mon script la commande :
type backup.log > backup1.log et c'est ce fichier backup1.log que je passe
en arguement du prog gbmail.
Le texte pert en lisibilité mais au moins passe...
Merci encore pour votre aide.
....


Avatar
ismans
Bonjour,

Pour ceux qui veulent utiliser des scripts plutôt qu'un executable, j'ai
enfin trouvé le sendmail.vbs bon a presque tout faire (Merci M. Bellamy):
Envoi de fichier attaché + incorporer un fichier texte en corps de message
(utilisation de la signature /s).

http://www.bellamyjc.org/download/vbs/sendmail.vbs

Il faut simplement ajouter le code permettant la définition des paramètres
relatif au server smtp qui par défaut est local dans ce script. Pour cela
remplacer la ligne :

Set objEmail = CreateObject("CDO.Message")

par

Const cdoSendUsingMethod =
"http://schemas.microsoft.com/cdo/configuration/sendusing", _
cdoSendUsingPort = 2, _
cdoSMTPServer = "http://schemas.microsoft.com/cdo/configuration/smtpserver"
'// Create the CDO connections.
Dim objEmail, iConf, Flds
Set objEmail = CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")
Set Flds = iConf.Fields

'// SMTP server configuration.
With Flds
.Item(cdoSendUsingMethod) = cdoSendUsingPort

'// Set the SMTP server address here.
.Item(cdoSMTPServer) = "192.168.0.2"
.Update
End With
Set objEmail.Configuration = iConf

Ce n'est pas très propre, mais cela fonctionne. M. Bellamy ajoutera
peut-être un jour les options de definition du serveur SMTP distant... si la
demande est forte :-)
Il pourrait même être intéressant de pouvoir passer un lien en argument :
voir

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cdo/html/_olemsg_adding_attachments_to_a_message.asp


Merci encore



Bonsoir,
Merci pour le retour
A+

"ismans" a écrit dans le message de
news:
Merci,

ce petit outil (GBmailer) qui fonctionne presque à merveille... Il
n'accepte

pas en entrée mon fichier log ntbakup : problème d'accentuation. J'ai dû
ajouter dans mon script la commande :
type backup.log > backup1.log et c'est ce fichier backup1.log que je passe
en arguement du prog gbmail.
Le texte pert en lisibilité mais au moins passe...
Merci encore pour votre aide.
....