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

VBScript Discussion :

Envoie mail script vbs


Sujet :

VBScript

  1. #1
    Membre éclairé
    Profil pro
    Inscrit en
    Février 2008
    Messages
    252
    Détails du profil
    Informations personnelles :
    Localisation : Suisse

    Informations forums :
    Inscription : Février 2008
    Messages : 252
    Par défaut Envoie mail script vbs
    Bonjour,

    Peut-on envoyer un e-mail avec un script vbs ?

    Si oui comment ?

    Merci

  2. #2
    Expert confirmé
    Avatar de ProgElecT
    Homme Profil pro
    Retraité
    Inscrit en
    Décembre 2004
    Messages
    6 124
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 69
    Localisation : France, Haute Savoie (Rhône Alpes)

    Informations professionnelles :
    Activité : Retraité
    Secteur : Communication - Médias

    Informations forums :
    Inscription : Décembre 2004
    Messages : 6 124
    Par défaut

    Je pense que tu n'as pas fait de recherches préalables.
    Rechercher dans ce forum avec le mot "mail", 120 réponses
    :whistle:pourquoi pas, pour remercier, un :plusser: pour celui/ceux qui vous ont dépannés.
    saut de ligne
    OOOOOOOOO👉 → → Ma page perso sur DVP ← ← 👈

  3. #3
    Membre éclairé
    Profil pro
    Inscrit en
    Février 2008
    Messages
    252
    Détails du profil
    Informations personnelles :
    Localisation : Suisse

    Informations forums :
    Inscription : Février 2008
    Messages : 252
    Par défaut
    Si mais je n'ai pas trouvé de post avec un script qui fonctionne .

    Quelqu'un pourrait modifier la partie configuration de ce code avec un serveut smtp connu comme celui de google afin que ce script marche ? Je me m'y connais pas en configuration du CDO.

    Code : 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
     
    Dim config As CDO.Configuration 
    Dim email As CDO.Message 
     
    Set config = New CDO.Configuration 
    With config.Fields 
        .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = CDO.cdoSendUsingPort 
        .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "le.smtp.google" 
        .Update 
    End With 
     
     
    Set email = New CDO.Message 
    With email 
        Set .Configuration = config 
        .From = "toto@a.com" 
        .To = "tata@a.com" 
        .Subject = "Sujet" 
        .Textbody = "Blabla" 
        .Send 
    End With

  4. #4
    Membre émérite
    Profil pro
    Inscrit en
    Janvier 2007
    Messages
    948
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2007
    Messages : 948
    Par défaut
    Déjà tu devrais essayer ton script sur un serveur SMTP à toi avec de vraies adresses, parce que meme si ton script etait correct google ne te laisserait pas envoyer ce mail (sinon tout le monde enverrait du spam via google avec des scripts).

  5. #5
    Membre régulier
    Profil pro
    Inscrit en
    Octobre 2009
    Messages
    8
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2009
    Messages : 8
    Par défaut
    http://www.developpez.net/forums/d82...oir-mails-vbs/

    Pour envoyer et recevoir.
    Si tu es chez free, de chez toi tu peux utiliser smtp.free.fr et ça fonctionne
    Par contre chez gmail le serveur smtp est bloqué tu ne peux donc pas utiliser une adresse google pour faire ton test.

    Courage

  6. #6
    Membre expérimenté
    Profil pro
    Inscrit en
    Juillet 2008
    Messages
    240
    Détails du profil
    Informations personnelles :
    Localisation : Suisse

    Informations forums :
    Inscription : Juillet 2008
    Messages : 240
    Par défaut
    Bonjour
    à tester avec le script précédent :

    en ajoutant, modifiant ses informations : smtp.gmail.com utilisation SSL.
    .Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465 'numéro du port du serveur d'envoie du mail
    .Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
    .Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
    .Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") = username ' remplacer
    .Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = password ' remplacer

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

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Juin 2009
    Messages : 3 841
    Par défaut
    Citation Envoyé par sokai Voir le message
    Si mais je n'ai pas trouvé de post avec un script qui fonctionne .
    Quelqu'un pourrait modifier la partie configuration de ce code avec un serveut smtp connu comme celui de google afin que ce script marche ? Je me m'y connais pas en configuration du CDO.

    Voici un exemple qui envoie un simple HTML E-Mail Message avec pièce jointe via les serveurs de Gmail en utilisant l'authentification SMTP et SSL.
    C'est comme tout autre courrier, mais exige que vous définissez le port SMTP à 465.
    Donc c'est juste vous deviez modifier la partie de l'authentification càd votre Login et votre mot de passe Gmail.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    '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
    Code : 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
    61
    62
    63
    64
    65
    66
    67
    68
    '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
     
    If Err.Number <>0 Then
    			MsgBox Err.Description,16,"Erreur"
    			msgbox "le mail n'a pas pu être envoyé !",16,"Information"
    		Else
    		msgbox "Le mail a été bien envoyé !",64,"Information"
    	End If
    		On Error GoTo 0

  8. #8
    Membre habitué
    Inscrit en
    Juin 2010
    Messages
    8
    Détails du profil
    Informations forums :
    Inscription : Juin 2010
    Messages : 8
    Par défaut Envoi E Mail format HTML dans le body
    Bonjour
    merci pour votre script
    j'ai un soucis avec le corps du texte en HTML

    sTable = "<html><body> ESSAI </body></html>"
    objEmail.HTMLBody = sTable

    ceci arrive dans ma messagerie comme une pièce jointe marque comme ci dessous

    Inconnu <text/html> (972 R) Aperçu | Télécharger | Supprimer

    si je clique sur Inconnu une page HTML s'ouvre

    je voudrais avoir ESSAI dans le corps du texte comme pour objEmail.TextBody

    merci pour votre aide

  9. #9
    Expert confirmé
    Avatar de hackoofr
    Homme Profil pro
    Enseignant
    Inscrit en
    Juin 2009
    Messages
    3 841
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 49
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Juin 2009
    Messages : 3 841

  10. #10
    Membre Expert

    Homme Profil pro
    Ingénieur Réseaux
    Inscrit en
    Juin 2012
    Messages
    877
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 33
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Ingénieur Réseaux
    Secteur : Conseil

    Informations forums :
    Inscription : Juin 2012
    Messages : 877
    Par défaut
    Bonjour,


    Jette un oeil à ce code :
    Code : 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
    'FONCTION ENVOI MAIL
    Function SendMail(strTo, strBody, strTitre)
    Set objMail = CreateObject("CDO.Message")
    Set objConfig = CreateObject("CDO.configuration")
    Set objFields = objConfig.Fields
    		With objFields
    			.Item("http://schemas.microsoft.com/cdo/configuration/SendUsing")= 2 'Définit le type d'envoi en SMTP
    			'Serveur Mail Interne
    			.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver")= "IP_SMTP"
    			.Item("http://schemas.microsoft.com/cdo/configuration/SMTPServerPort")= 25
    			.Update
    		End With
    		With objMail
    			Set .Configuration = objConfig
    			.To = strTo
    			.Cc = strCc
    			.Bcc = strBcc
    			.AddAttachment("logo.jpg")
    			.From = "test@test.com"
    			.Subject = strTitre
    			.HTMLBody = strBody 
    			.Send
    	    End With
    End Function

Discussions similaires

  1. [Débutant] Forcer envoie email - script vbs
    Par yoyohand dans le forum EDI/Outils
    Réponses: 0
    Dernier message: 13/01/2015, 17h52
  2. Réponses: 2
    Dernier message: 01/11/2014, 10h27
  3. Envoi mail script en vbs
    Par nathalie.de dans le forum VBScript
    Réponses: 6
    Dernier message: 19/09/2014, 13h55
  4. Réponses: 2
    Dernier message: 12/05/2014, 13h20
  5. script envoi mail et fax avec CDO
    Par RobinNono dans le forum ASP
    Réponses: 1
    Dernier message: 03/10/2005, 15h36

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