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

Vos Contributions VBScript Discussion :

[HTA] SMTP Mail Client avec pièce jointe


Sujet :

Vos Contributions VBScript

  1. #1
    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 [HTA] SMTP Mail Client avec pièce jointe
    voila un exemple de Formulaire en HTML Application HTA pour envoyer un e-mail avec pièce-jointe par deux méthodes:
    1-Via le serveur Gmail en utilisant l'authentification SMTP et SSL de ce dernier
    2-Via Votre Serveur SMTP sans authentification
    NB: Pour la 2ème méthode on peut l'utiliser sans login et sans mot de passe si on est sous le même Domaine et on peut aussi l'utiliser aussi si on est devant un Proxy , il suffit juste remplacer le contenu du champ SMTP "smtp.serveur.com"par son adresse IP par exemple si votre Proxy a comme adresse IP 172.16.0.1 ou bien 192.168.1.1
    ( A vérifier chez vous )

    Donc Copier/Coller ce code et enregister-le sous Mail.hta par exemple
    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
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    <html> 
    <head> 
    <HTA:APPLICATION 
        ICON="icon.ico"
        APPLICATIONNAME = "SMTP Mail Client" 
        BORDER="dialog"
        BORDERSTYLE="complex"
        CONTEXTMENU="no"
        SYSMENU="yes"
        MAXIMIZEBUTTON="no"
        SCROLL="no" 
    >
    <title>SMTP Mail Client © Hackoo</title> 
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> 
    <style>
        body{
            background-color: lightblue;
        }
        label,.btn{
            font-weight: bold;
        }
    </style>
    <script language="VBScript">
    Const cdoSendUsingPickup = 1 
    Const cdoSendUsingPort = 2 'Must use this to use Delivery Notification
    Const cdoAnonymous = 0
    Const cdoBasic = 1 ' clear text
    Const cdoNTLM = 2 'NTLM
    'Delivery Status Notifications
    Const cdoDSNDefault = 0 'None
    Const cdoDSNNever = 1 'None
    Const cdoDSNFailure = 2 'Failure
    Const cdoDSNSuccess = 4 'Success
    Const cdoDSNDelay = 8 'Delay
    Const cdoDSNSuccessFailOrDelay = 14 'Success, failure or delay
    messageSSLHTML = "<center><font size=4 FACE=Comic sans MS style=font-weight:bold Color=red Color=red>Ceci est un exemple de message en HTML.<br>Il a été envoyé en utilisant l'authentification SMTP et SSL.<br><br>"
    Signature = "<center><font size=10 FACE=Comic sans MS style=font-weight:bold Color=red><br>©<br><img src=http://photomaniak.com/upload/out.php/i1102064_IDNlogo.gif>" 
     
    Sub ViaGmail
    Dim f1
    f1 = file.Value
    Login = InputBox ("Donner Votre adresse email  !", "ADRESSE GMAIL DU EXPEDITEUR", "moi@gmail.com") 
    Password = InputBox ("Donner Votre Mot de passe email  !", "VOTRE MOT DE PASSE GMAIL", "")
    GmailBox=MsgBox ("Envoi avec ces Options:" & vbCrLf &"Expéditeur :"& Login & vbCrLf & "Destinataire : "& txtTo.Value &  vbCrLf & "Sujet :" & txtSubject.Value & vbCrLf & "FileAttach1 :"& f1 ,vbYesNo+64,"Message Options")
        If GmailBox = vbYes Then 
    	if  SendGmailSSL(Login,Password, txtTo.Value, txtSubject.Value, txtBody.value+messageSSLHTML+Signature,f1)= 0  Then
     
        MsgBox "Le Mail a été envoyé avec succès !",vbInformation ,"Information"
        Else
     
        MsgBox "Echec d'envoi du Mail !",vbExclamation ,"Information"
        End If
        End If
    End Sub
     
    Function SendGmailSSL( sFrom, sPassword, sTO ,sSubject, sBody, sFilePath1)
     
        Set objMessage = CreateObject("CDO.Message") 
        objMessage.Subject = sSubject 
        objMessage.From = sFrom
        objMessage.To = sTO
        objMessage.HTMLBody = sBody 
        If sFilePath1 <> "" Then
            objMessage.AddAttachment sFilePath1   
        End If
     
        objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 
        objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com" 
        objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
        objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = sFrom
        objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = sPassword
        objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
        objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
        objMessage.Configuration.Fields.Update
     
        On Error Resume Next
        objMessage.Send
        SendGmailSSL = Err.Number
        If Err.Number <> 0  Then
            MsgBox Err.Description, 16, "SendGmailSSL Erreur"
        End If
     
    End Function
     
     
        Sub window_onload()
            CenterWindow 415, 600
        End Sub
     
        Sub CenterWindow(x,y)
            window.resizeTo x, y
            iLeft = window.screen.availWidth/2 - x/2
            itop = window.screen.availHeight/2 - y/2
            window.moveTo ileft, itop
        End Sub
     
        Sub SendMail()
            SendMailMessage txtFrom.Value, txtTo.Value, txtSubject.Value, txtBody.value ,txtSMTPSERVER.Value, file.Value      
        End Sub
     
        Sub SendMailMessage( sFrom, sTo, sSubject, sBody, SMTPSERVER, File)
            MsgBox "Envoi du Mail avec ces options:"& vbCrLf &"Expéditeur: "& sFrom & vbCrLf & "To: " & sTo & vbCrLf &"Sujet: " & sSubject & vbCrLf &"Text Message: " & sBody & vbCrLf & "SMTP SERVER: " & SMTPSERVER & vbCrLf & "Piéce-jointe: " & File,64,"Send Email"
            messageHTML="<center><font size=4 FACE=Comic sans MS style=font-weight:bold Color=red>Ceci est un exemple de message avec Signature en HTML <br> envoyé par Hackoo !" 
            File = document.getElementById("file").Value 
     
            Set msg = CreateObject("CDO.Message") 
            With msg
                .From = sFrom
                .To = sTo 
                .Subject = sSubject
                .TextBody = sBody 
                .HTMLBody=sBody & messageHTML & Signature 
                .Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 
                .Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = SMTPSERVER 
                .Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 
                If File <> "" Then
                   .AddAttachment File  'Ajout de la piéce-jointe
                End If  
                .Configuration.Fields.Update 
                On Error Resume Next
                .Send
                If Err.Number <>0 Then 
                    MsgBox Err.Description,16,"Error Sending Mail"
                Else 
                    MsgBox "Le Mail a été envoyé avec succès !",64,"Information" 
                End If
     
            End With
     
        End Sub
    </script> 
    </head> 
     
    <body> 
     
        <label for="Expéditeur" style="width: 120; textalign: right;">Expéditeur:</label><input type="text" id="txtFrom" name="Expéditeur" value="Expéditeur@gmail.com"><br /> 
        <label for="to" style="width: 120; textalign: right;">Destinataire:</label><input type="text" id="txtTo" name="to" value="Destinataire@gmail.com"><br />
        <label for="subject" style="width: 120; textalign: right;">Sujet:</label><input type="text" id="txtSubject" name="sujet" value="Sujet"><br />
        <label for="txtSMTPSERVER" style="width: 120; textalign: right;">SMTP:</label><input type="text" id="txtSMTPSERVER" name="txtSMTPSERVER" value="smtp.serveur.com"><br />
        <label for="file">Pièce-Jointe :</label><br />
        <input type="file" name="file" id="file" /><br>
        <label>Message:</label><br />
        <textarea id="txtBody" rows="20" cols="45"></textarea><br><br>
        <center>
        <input class="btn" type="button" value="Envoyer Via Gmail" onClick="ViaGmail">
        <input class="btn" type="button" value="Envoyer Via SMTP" onClick="SendMail">
    </body> 
    </html>
    J'attends vos tests et vos commentaires


  2. #2
    Inactif  

    Homme Profil pro
    cuisiniste
    Inscrit en
    Avril 2009
    Messages
    15 379
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Var (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : cuisiniste
    Secteur : Bâtiment

    Informations forums :
    Inscription : Avril 2009
    Messages : 15 379
    Points : 12 075
    Points
    12 075
    Billets dans le blog
    8
    Par défaut heu
    bonjour hackoofr


    jai trouver ton code bien pratique

    il y avais un petit detail cependant qui me genait

    le texte du texaera sur plusieures lignes se retrouvait sur une seule ligne dans le message

    il a falu formater le texte au format html

    je l'ai un peu remanier a ma sauce

    j'ai remplacer le textbox expediteur par une combobox pour avoir mon email pro et privé
    j'ai supprimer aussi la fonction gmail inutile pour moi

    pour le text j'ai utilisé une boucle avec la fonction split par les saut de ligne

    enfin voila ce que ca donne

    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
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
     
    <html> 
    <head> 
    <HTA:APPLICATION 
        ICON="icon.ico"
        APPLICATIONNAME = "ENVOYER UN MAIL" 
        BORDER="dialog"
        BORDERSTYLE="complex"
        CONTEXTMENU="yes"
        SYSMENU="yes"
        MAXIMIZEBUTTON="yes"
        SCROLL="no" 
    CAPTION="no"
    >
    <title>MAILERS</title> 
    <style>
        body 
    {
      color:black;
      background-color:white;
      background-image:url(fond.jpg);
      background-repeat:no-repeat;
    }        
        label,.btn{
            font-weight: bold;
        }
    </style>
    <script language="VBScript">
     
     
    Sub window_onload()
            CenterWindow 900, 600
        End Sub
     
    Sub CenterWindow(x,y)
            window.resizeTo x, y
            iLeft = window.screen.availWidth/2 - x/2
            itop = window.screen.availHeight/2 - y/2
            window.moveTo ileft, itop
        End Sub
     
     
     
     
     
     
     
     
     
        Sub SendMail()
     
    if txtTo.value="" then 
    msgbox "entrez d'abors un destinataire"
    exit sub
    end if
    lien="<A href=mailto:toto@msn.com>toto@msn.com</A>"
     
     
    ' on va transformer le textaera au format html (chaque ligne entre balises)
         Dim st,i,tb,files
    dim paragraphe
    st=txtbody.value
    tb = split(st,vbcrlf)
    For i = lbound(tb) to ubound(tb)
      paragraphe=paragraphe & tb(i) & "<br>" & vbcrlf
    next
    paragraphe=paragraphe & "<br><br>"& _
    "<center><font size=4 FACE=Comic sans MS style=font-weight:bold  Color=violet>POUR TOUT RESEIGNEMENT<br>OU TOUTES QUESTION CLIQUER SUR LE LIEN POUR ME CONTACTER<br><br>" & lien
     
     
     
            Files = file.Value 
           msgbox file.Value & vbcrlf & txtTo.value
            Set msg = CreateObject("CDO.Message") 
            With msg
                .From = lstChaines.value 
     
                .To = txtTo.value
     
                .Subject = txtSubject
     
                .HTMLBody=paragraphe
                .Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 
                .Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = txtSMTPSERVER.Value'SMTPSERVER 
                .Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 
                If File.value <> "" Then
                   .AddAttachment File.value  'Ajout de la piéce-jointe
                End If  
                .Configuration.Fields.Update 
                On Error Resume Next
                .Send
                If Err.Number <>0 Then 
                    MsgBox Err.Description,16,"Error Sending Mail"
                Else 
               if file.value="" then piece=""     
    if file.value<>"" then piece = "avecle fichier " & vbcrlf &  file.value & vbcrlf & "en piece jointe"
     
    MsgBox "Le Mail a été envoyé avec succès !"& vbcrlf & " à" & vbcrlf & txtTo.value & vbcrlf & piece,64,"Information" 
                End If
     
            End With
     
        End Sub
     
    sub fermeture()
    window.close
    end sub 
     
    </script> 
    </head> 
     
    <body> 
        <font color="#FFFF33">
        <label for="Expéditeur"   style="width: 120 color=#FFFF00; textalign: right;">Expéditeur:</label><SELECT NAME="lstChaines" SIZE=1>
     
    <OPTION VALUE="toto@msn.com">toto@msn.com
    <OPTION VALUE="titi@msn.com">titi@msn.com
    </SELECT> 
     
     
     
     
    <br /> 
     
    <label for="to" style="width: 120; textalign: right;">Destinataire:</label><input type="text" id="txtTo" name="to" value=""><br />
        <label for="subject" style="width: 120; textalign: right;">Sujet:</label><input type="text" id="txtSubject" name="sujet" value="Sujet"><br />
        <label for="txtSMTPSERVER" style="width: 120; textalign: right;">SMTP:</label><input type="text" id="txtSMTPSERVER" name="txtSMTPSERVER" value="smtp.aliceadsl.fr"><br />
        <label for="file">Pièce-Jointe :</label><br />
        <input type="file" name="file" id="file" /><br>
        <label>Message:</label><br />
        <textarea id="txtBody" rows="20" cols="80"></textarea><br><br>
        <center>
     
        <input class="btn" type="button" value="ENVOYER" onClick="SendMail">
     
        <input class="btn" type="button" value="fermer"; onClick="fermeture">
     
    </body> 
    </html>

    qu'en pense tu ?


    au plaisir
    mes fichiers dans les contributions:
    mail avec CDO en vba et mail avec CDO en vbs dans un HTA
    survol des bouton dans userform
    prendre un cliché d'un range

    si ton problème est résolu n'oublie pas de pointer : : ça peut servir aux autres
    et n'oublie pas de voter

  3. #3
    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 patricktoulon Voir le message
    pour le texte j'ai utilisé une boucle avec la fonction split par les saut de ligne

    J'apprécie cette modification surtout le formatage du texte c'est très pratique
    je vais l'utiliser pour la mise à jour

  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 Mise à jour : "Formater le textaera au format html"

    c'est une petite mise à jour pour Formater le textaera au format html pour contourner le problème du message qui s'affiche sur une seule ligne
    Un Grand à patricktoulon pour cette Astuce
    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
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    <html> 
    <head> 
    <HTA:APPLICATION 
        ICON="icon.ico"
        APPLICATIONNAME = "SMTP Mail Client" 
        BORDER="dialog"
        BORDERSTYLE="complex"
        CONTEXTMENU="no"
        SYSMENU="yes"
        MAXIMIZEBUTTON="no"
        SCROLL="no" 
    >
    <title>SMTP Mail Client © Hackoo</title> 
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> 
    <style>
        body{
            background-color: lightblue;
        }
        label,.btn{
            font-weight: bold;
        }
    </style>
    <script language="VBScript">
    Const cdoSendUsingPickup = 1 
    Const cdoSendUsingPort = 2 'Must use this to use Delivery Notification
    Const cdoAnonymous = 0
    Const cdoBasic = 1 ' clear text
    Const cdoNTLM = 2 'NTLM
    'Delivery Status Notifications
    Const cdoDSNDefault = 0 'None
    Const cdoDSNNever = 1 'None
    Const cdoDSNFailure = 2 'Failure
    Const cdoDSNSuccess = 4 'Success
    Const cdoDSNDelay = 8 'Delay
    Const cdoDSNSuccessFailOrDelay = 14 'Success, failure or delay
    messageSSLHTML = "<center><font size=4 FACE=Comic sans MS style=font-weight:bold Color=red Color=red>Ceci est un exemple de message en HTML.<br>Il a été envoyé en utilisant l'authentification SMTP et SSL.<br><br>"
    Signature = "<center><font size=10 FACE=Comic sans MS style=font-weight:bold Color=red><br>©<br><img src=http://photomaniak.com/upload/out.php/i1102064_IDNlogo.gif>" 
     
     
     
    Sub ViaGmail
    'Formater le textaera au format html pour contourner le problème du message qui s'affiche sur une seule ligne
    'Un Grand Merci à patrick pour cette Astuce
    Dim st,i,tb,f1,paragraphe
    st=txtbody.value
    tb = split(st,vbcrlf)
    For i = lbound(tb) to ubound(tb)
      paragraphe=paragraphe & tb(i) & "<br>" & vbcrlf
    Next
     
    f1 = file.Value
    Login = InputBox ("Donner Votre adresse email  !", "ADRESSE GMAIL DU EXPEDITEUR", "moi@gmail.com") 
    Password = InputBox ("Donner Votre Mot de passe email  !", "VOTRE MOT DE PASSE GMAIL", "")
    GmailBox=MsgBox ("Envoi avec ces Options:" & vbCrLf &"Expéditeur :"& Login & vbCrLf & "Destinataire : "& txtTo.Value &  vbCrLf & "Sujet :" & txtSubject.Value & vbCrLf & "FileAttach1 :"& f1 ,vbYesNo+64,"Message Options")
        If GmailBox = vbYes Then 
    	if  SendGmailSSL(Login,Password, txtTo.Value, txtSubject.Value, paragraphe+messageSSLHTML+Signature,f1)= 0  Then
     
        MsgBox "Le Mail a été envoyé avec succès !",vbInformation ,"Information"
        Else
     
        MsgBox "Echec d'envoi du Mail !",vbExclamation ,"Information"
        End If
        End If
    End Sub
     
    Function SendGmailSSL( sFrom, sPassword, sTO ,sSubject, sBody, sFilePath1)
     
     
        Set objMessage = CreateObject("CDO.Message") 
        objMessage.Subject = sSubject 
        objMessage.From = sFrom
        objMessage.To = sTO
     
        objMessage.HTMLBody = sBody 
        If sFilePath1 <> "" Then
            objMessage.AddAttachment sFilePath1   
        End If
     
        objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 
        objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com" 
        objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
        objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = sFrom
        objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = sPassword
        objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
        objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
        objMessage.Configuration.Fields.Update
     
        On Error Resume Next
        objMessage.Send
        SendGmailSSL = Err.Number
        If Err.Number <> 0  Then
            MsgBox Err.Description, 16, "SendGmailSSL Erreur"
        End If
     
    End Function
     
     
        Sub window_onload()
            CenterWindow 415, 600
        End Sub
     
        Sub CenterWindow(x,y)
            window.resizeTo x, y
            iLeft = window.screen.availWidth/2 - x/2
            itop = window.screen.availHeight/2 - y/2
            window.moveTo ileft, itop
        End Sub
     
    Sub SendMail()
    'Formater le textaera au format html 
    Dim st,i,tb,paragraphe
    st=txtbody.value
    tb = split(st,vbcrlf)
    For i = lbound(tb) to ubound(tb)
      paragraphe=paragraphe & tb(i) & "<br>" & vbcrlf
    Next
      SendMailMessage txtFrom.Value, txtTo.Value, txtSubject.Value, paragraphe ,txtSMTPSERVER.Value, file.Value      
        End Sub
     
        Sub SendMailMessage( sFrom, sTo, sSubject, sBody, SMTPSERVER, File)
            MsgBox "Envoi du Mail avec ces options:"& vbCrLf &"Expéditeur: "& sFrom & vbCrLf & "To: " & sTo & vbCrLf &"Sujet: " & sSubject & vbCrLf &"Text Message: " & sBody & vbCrLf & "SMTP SERVER: " & SMTPSERVER & vbCrLf & "Piéce-jointe: " & File,64,"Send Email"
            messageHTML="<center><font size=4 FACE=Comic sans MS style=font-weight:bold Color=red>Ceci est un exemple de message avec Signature en HTML <br> envoyé par Hackoo !" 
            File = document.getElementById("file").Value 
     
            Set msg = CreateObject("CDO.Message") 
            With msg
                .From = sFrom
                .To = sTo 
                .Subject = sSubject
                .TextBody = sBody 
                .HTMLBody=sBody & messageHTML & Signature 
                .Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 
                .Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = SMTPSERVER 
                .Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 
                If File <> "" Then
                   .AddAttachment File  'Ajout de la piéce-jointe
                End If  
                .Configuration.Fields.Update 
                On Error Resume Next
                .Send
                If Err.Number <>0 Then 
                    MsgBox Err.Description,16,"Error Sending Mail"
                Else 
                    MsgBox "Le Mail a été envoyé avec succès !",64,"Information" 
                End If
     
            End With
     
        End Sub
    </script> 
    </head> 
     
    <body> 
     
        <label for="Expéditeur" style="width: 120; textalign: right;">Expéditeur:</label><input type="text" id="txtFrom" name="Expéditeur" value="Expéditeur@gmail.com"><br /> 
        <label for="to" style="width: 120; textalign: right;">Destinataire:</label><input type="text" id="txtTo" name="to" value="Destinataire@gmail.com"><br />
        <label for="subject" style="width: 120; textalign: right;">Sujet:</label><input type="text" id="txtSubject" name="sujet" value="Sujet"><br />
        <label for="txtSMTPSERVER" style="width: 120; textalign: right;">SMTP:</label><input type="text" id="txtSMTPSERVER" name="txtSMTPSERVER" value="smtp.orange.fr"><br />
        <label for="file">Pièce-Jointe :</label><br />
        <input type="file" name="file" id="file" /><br>
        <label>Message:</label><br />
        <textarea id="txtBody" rows="20" cols="45"></textarea><br><br>
        <center>
        <input class="btn" type="button" value="Envoyer Via Gmail" onClick="ViaGmail">
        <input class="btn" type="button" value="Envoyer Via SMTP" onClick="SendMail">
    </body> 
    </html>

  5. #5
    Inactif  

    Homme Profil pro
    cuisiniste
    Inscrit en
    Avril 2009
    Messages
    15 379
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Var (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : cuisiniste
    Secteur : Bâtiment

    Informations forums :
    Inscription : Avril 2009
    Messages : 15 379
    Points : 12 075
    Points
    12 075
    Billets dans le blog
    8
    Par défaut re
    bonjour

    ya pas de quoi


    voila un bon petit formulaire qui passe partout


    au plaisir
    mes fichiers dans les contributions:
    mail avec CDO en vba et mail avec CDO en vbs dans un HTA
    survol des bouton dans userform
    prendre un cliché d'un range

    si ton problème est résolu n'oublie pas de pointer : : ça peut servir aux autres
    et n'oublie pas de voter

  6. #6
    Membre à l'essai
    Homme Profil pro
    Auditeur informatique
    Inscrit en
    Novembre 2011
    Messages
    10
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Vaucluse (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Auditeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Novembre 2011
    Messages : 10
    Points : 10
    Points
    10
    Par défaut re
    y a un probleme pour moi il me dit que le mail a ete envoyer mais je ne le recois pas

  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 pkplomb Voir le message
    y a un probleme pour moi il me dit que le mail a ete envoyer mais je ne le recois pas

    tu as envoyer avec quoi ? je veux dire avec le smtp de ton provider ou bien avec le smtp de Gmail ?

Discussions similaires

  1. Envoi de mail texte avec pièce jointe quelconque
    Par Heremion dans le forum Langage
    Réponses: 27
    Dernier message: 12/05/2014, 00h48
  2. Envoyer mails automatiquement avec pièce jointe
    Par couriel dans le forum Langages de programmation
    Réponses: 1
    Dernier message: 31/08/2012, 13h28
  3. e-mails automatiques avec pièce jointe
    Par touche_a_tout dans le forum Macros et VBA Excel
    Réponses: 2
    Dernier message: 28/02/2012, 10h20
  4. [Mail] problème mail html avec pièce jointe
    Par stars333 dans le forum Langage
    Réponses: 2
    Dernier message: 12/06/2007, 19h44
  5. [Mail] Problème avec pièce jointe
    Par coco38 dans le forum Langage
    Réponses: 4
    Dernier message: 27/04/2007, 10h14

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