IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Scripts/Batch Discussion :

Envoi mail via script batch [Batch]


Sujet :

Scripts/Batch

  1. #1
    Membre averti
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Juin 2013
    Messages
    933
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Juin 2013
    Messages : 933
    Points : 348
    Points
    348
    Par défaut Envoi mail via script batch
    Bonjour

    est il possible d'envoyer un mail via un script batch ?

    j'ai un script qui transfère des fichiers et j'aimerais être averti par mail, ainsi qu'envoyer un mail automatique ( via une ligne de commande dans mon script batch) pour nosu avertir que c'est bon.

    j'ai trouvé ceci pour commencer

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    start mailto:vincent@xxxx.fr?subject=sujet^&body=CorpsDuMessage
    mais ça m'ouvre Outlook et un nouveau mail et ce que j'aimerais c'est que le mail s'envoie automatiquement, c'est à dire quand le script se lance, à la fin je reçois un mail, ainsi qu'une autre personne, est ce possible ?

    Merci à vous

  2. #2
    Membre éprouvé
    Homme Profil pro
    Développeur .NET en devenir
    Inscrit en
    Août 2017
    Messages
    546
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 45
    Localisation : France, Moselle (Lorraine)

    Informations professionnelles :
    Activité : Développeur .NET en devenir
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Août 2017
    Messages : 546
    Points : 1 084
    Points
    1 084
    Par défaut
    Bonjour,

    C'est possible en passant par une commande externe telle que Blat ou bien SwithMail :

    - https://www.blat.net/

    - https://www.tbare.com/software/swithmail/

    Personnellement j'utilise SwithMail, il y a même une interface graphique qui te permettra de générer un fichier XML contenant les paramètres d'envoi ainsi que le message lui-même.

  3. #3
    Membre averti
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Juin 2013
    Messages
    933
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Juin 2013
    Messages : 933
    Points : 348
    Points
    348
    Par défaut
    Bonjour,

    n'y a t-il pas un autre moyen plus simple car j'ai du mal a configuré le logiciel.
    J'ai trouvé également ceci, pour tenté de le faire avec un script vbs

    Code VB : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    'This sample sends a simple HTML EMail Message with Attachment File via GMail servers using SMTP authentication and SSL.
    'It's like any other mail but requires that you set the SMTP Port to 465 and tell CDO to use SSL
    'By Hackoo © 2011
    On Error Resume Next
    Const cdoSendUsingPickup = 1 'Send message using the local SMTP service pickup directory. 
    Const cdoSendUsingPort = 2 'Send the message using the network (SMTP over the network). 
    Const cdoAnonymous = 0 'Do not authenticate
    Const cdoBasic = 1 'basic (clear-text) authentication
    Const cdoNTLM = 2 'NTLM
    sFilePath="C:\SSLGmail.rar" 'Path of the Attached File
    Set objMessage = CreateObject("CDO.Message") 
    objMessage.Subject = "Example CDO Message" 
    objMessage.From = """Me"" <Mymail@gmail.com>" 'change this to yours
    objMessage.To = "dest@yahoo.fr" 'change this To
    objMessage.CC = "dest2@yahoo.fr" 'change this CC means : Carbon Copy
    objMessage.BCC = "dest3@gmail.com" 'change this BCC means : Blink Carbon Copy
    sBody = "<center><font size=4 FACE=Tahoma Color=red>This is some sample message in HTML.<br> It was sent using SMTP authentication and SSL."
    objMessage.HTMLBody = sBody  & _
         "<center><font size=4 FACE=Tahoma Color=red>" & _
          messageHTML & _ 
         "<br><br><img src=http://photomaniak.com/upload/out.php/i1102064_IDNlogo.gif>" 
    objMessage.AddAttachment sFilePath   
    '==This section provides the configuration information for the remote SMTP server.
     
    objMessage.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 
     
    'Name or IP of Remote SMTP Server
    objMessage.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com" 'SMTP SERVER of GMAIL must be inchanged
     
    'Type of authentication, NONE, Basic (Base64 encoded), NTLM
    objMessage.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoBasic
     
    'Your UserID on the SMTP server
    objMessage.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/sendusername") = "YourLoginGmail@gmail.com" 'change this to yours
     
    'Your password on the SMTP server
    objMessage.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "YourPasswordGmail" 'change this to yours
     
    'Server port (typically 25 and 465 in SSL mode for Gmail)
    objMessage.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465 'don't change this
     
    'Use SSL for the connection (False or True)
    objMessage.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
     
    'Connection Timeout in seconds (the maximum time CDO will try to establish a connection to the SMTP server)
    objMessage.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
     
    objMessage.Configuration.Fields.Update
     
    '==End remote SMTP server configuration section==
     
    objMessage.Send
    mais ça n'a pas l'air de marché

    pour information, j'ai une adresse office 365, j'ai utilisé les paramètres suivants :

    Utilisez outlook.office365.com pour les paramètres de serveur entrant.
    Utilisez smtp.office365.com pour les paramètres de serveur SMTP sortant.
    Port entrant : 993 pour IMAP ou 995 pour POP.
    Numéro du port sortant : 587.
    mais quand je clique sur mon script rien ne se passe.

    Petite question, comme j'appel start mailto dans mon batch n'y a il pas d'autres ligne de commande pour envoyer le mail automatiquement ?

    merci beaucoup !

  4. #4
    Expert éminent
    Avatar de hackoofr
    Homme Profil pro
    Enseignant
    Inscrit en
    Juin 2009
    Messages
    3 839
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 48
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Juin 2009
    Messages : 3 839
    Points : 9 222
    Points
    9 222
    Par défaut

    Tout d'abord il faut bien vérifier les paramèters de sécurité de votre gmail ici : https://www.google.com/settings/security/lesssecureapps
    Il faut que le paramètre "Autoriser les applications moins sécurisées" soit activé

    Code vb : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    Const cdoSendUsingPickup = 1 'Send message using the local SMTP service pickup directory.
    Const cdoSendUsingPort = 2 'Send the message using the network (SMTP over the network).
    Const cdoAnonymous = 0 'Do not authenticate
    Const cdoBasic = 1 'basic (clear-text) authentication
    Const cdoNTLM = 2 'NTLM
    '===========================================================
    EmailSender = "VotreLogin@gmail.com" 'à changer
    PassGmail = "VotrePassGmail" 'à changer
    Email_Destinataire = "TOTO@yahoo.fr" 'à changer
    '===========================================================
    Set objMessage = CreateObject("CDO.Message")
    objMessage.Subject = "Example CDO Message"
    objMessage.From = """Me"" <"& EmailSender &">"
    objMessage.To = Email_Destinataire 
    objMessage.HTMLBody = "<H1>Ceci est exemple d'envoi mail ...</H1><br><h2>It was sent using SMTP authentication and SSL.</h2>"
     
    '==This section provides the configuration information for the remote SMTP server.
     
    objMessage.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
     
    'Name or IP of Remote SMTP Server
    objMessage.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
     
    'Type of authentication, NONE, Basic (Base64 encoded), NTLM
    objMessage.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoBasic
     
    'Your UserID on the SMTP server
    objMessage.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/sendusername") = EmailSender
     
    'Your password on the SMTP server
    objMessage.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = PassGmail 
     
    'Server port (typically 25)
    objMessage.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
     
    'Use SSL for the connection (False or True)
    objMessage.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
     
    'Connection Timeout in seconds (the maximum time CDO will try to establish a connection to the SMTP server)
    objMessage.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
     
    objMessage.Configuration.Fields.Update
     
    '==End remote SMTP server configuration section==
    On Error Resume Next
    objMessage.Send
    If err<> o Then
    Msgbox Err.Description,vbCritical,Err.Description
    else
    MsgBox "Message envoyé avec succés !",VbInformation,"Message envoyé avec succés !"
    end if

  5. #5
    Membre averti
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Juin 2013
    Messages
    933
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Juin 2013
    Messages : 933
    Points : 348
    Points
    348
    Par défaut
    merci pour ton retour

    je suis tombé sur ce morceau de code :
    Code VB : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    On Error Resume Next
    RCP = "mon_mailpro@xx.fr"
    MSG = "mon message" 
    SUBJ = "Mail automatique : objet"
    Set Outlook = CreateObject("Outlook.Application")
    Set MAPI = Outlook.GetNameSpace("MAPI")
    Set NewMail = OUtlook.CreateItem(0)
    NewMail.Subject = SUBJ
    NewMail.Body = MSG
    NewMail.Recipients.Add RCP
    NewMail.Cc="perso1encopie@xx.fr;person2@cc.fr"
    NewMail.Send

    en fait j'ai décidé de passer par ce petit script, et dans mon batch je mets juste Call etc. (j'appelle mon script) et ça marche tout seul

    merci !

  6. #6
    Membre averti
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Juin 2013
    Messages
    933
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Juin 2013
    Messages : 933
    Points : 348
    Points
    348
    Par défaut
    pour finir ça ne marche pas mdr lorsque mon batch appel mon script, j'ai un autre programme qui empêche l'execution des scripts vbs lol.

    n'y aurait-il pas un moyen d'envoyer un mail en batch ou de contourner le problème? j'ai tenté de mettre mon fichier script dans la zone approuver mais il ne veut pas :s

  7. #7
    Expert éminent
    Avatar de hackoofr
    Homme Profil pro
    Enseignant
    Inscrit en
    Juin 2009
    Messages
    3 839
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 48
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Juin 2009
    Messages : 3 839
    Points : 9 222
    Points
    9 222
    Par défaut
    Citation Envoyé par android59 Voir le message
    pour finir ça ne marche pas mdr lorsque mon batch appel mon script, j'ai un autre programme qui empêche l'execution des scripts vbs
    C'est quoi comme programme qui empéche l'exécution du vbscript ?

  8. #8
    Membre averti
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Juin 2013
    Messages
    933
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Juin 2013
    Messages : 933
    Points : 348
    Points
    348
    Par défaut
    Bonjour,

    il s'appel Marmiton interceptor, finalement on m'a dit que je pouvais l'enlever.

    je suis confronté à un autre soucis, moi qui pensé en avoir fini :s après avoir testé mon batch, quand il arrive à l'instruction " Call monfichier.vbs " pour l'envoie de mail, il m'ouvre une fenêtre " ouvrir avec... " alors là je sèche lol .

    En local sur mon ordi ça marche nickel, mais sur mon serveur, je comprend pas trop comment faire pour l’exécuter, si je ferme la fenêtre , dans la fenêtre de commande il me dit " accès refusé " :s
    Pour exécuter les scripts vbs il faut qu'un programme spécifique soit installé sur le serveur ?

    Merci !

  9. #9
    Membre averti
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Juin 2013
    Messages
    933
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Juin 2013
    Messages : 933
    Points : 348
    Points
    348
    Par défaut
    Problème résolu, j'ai un programme qui envoie de mail, appelé par un script batch

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Envoi mail via une liste de contact
    Par Djohn dans le forum Macros et VBA Excel
    Réponses: 3
    Dernier message: 23/10/2007, 15h55
  2. Envoi Mail via Access
    Par p935754 dans le forum VBA Access
    Réponses: 2
    Dernier message: 25/08/2007, 11h09
  3. Envoie Mail via Nescape et thunderbird
    Par foxer98 dans le forum Macros et VBA Excel
    Réponses: 5
    Dernier message: 20/07/2007, 13h47
  4. Envoi mail via telnet
    Par Bourriquette dans le forum Programmation et administration système
    Réponses: 2
    Dernier message: 14/03/2007, 10h03
  5. procedure envoie mail via OUTLOOK
    Par laurent1 dans le forum Oracle
    Réponses: 13
    Dernier message: 22/10/2006, 10h16

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo