joindre un fichier avec Outlook via un script

Aide et conseils concernant AutoIt et ses outils.
Règles du forum
.
Répondre
yohanb767
Niveau 5
Niveau 5
Messages : 117
Enregistré le : mer. 28 déc. 2016 14:09
Status : Hors ligne

joindre un fichier avec Outlook via un script

#1

Message par yohanb767 »

Bonjour j'ai un script qui me permet d'envoyer un mail déjà pré remplie mais j'aimerai y ajouter un fichier joint
voici mon code

si quelqu'un aurai la gentillesse de m'aider merci d'avance
Yohan

Code : Tout sélectionner

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 267, 203, 427, 339)
$Label1 = GUICtrlCreateLabel("Envoi Du Mail", 72, 16, 120, 28)
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
$Label2 = GUICtrlCreateLabel("A L'Atelier", 40, 40, 180, 28)
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
$Pic2 = GUICtrlCreatePic("C:\Users\Pictures\image-de-mail.jpg", 80, 72, 100, 76)
$OK = GUICtrlCreateButton("OK", 24, 152, 97, 33)
GUICtrlSetOnEvent($OK, "OK")
$Annuler = GUICtrlCreateButton("Annuler", 144, 152, 97, 33)
GUICtrlSetOnEvent($Annuler, "Annuler")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
                $nMsg = GUIGetMsg()
                Switch $nMsg
                               Case $GUI_EVENT_CLOSE
                                               Exit
                               Case $OK
Local $olMailItem = 0
Local $olFormatRichText = 3
Local $olImportanceLow = 0
Local $olImportanceNormal = 1
Local $olImportanceHigh = 2
Local $olByValue = 1
Local $olFormatHTML = 2
Local $olFormatPlain = 1

Local $objet = "Essai"
Local $mailto = "" ; Adresse d'envoi
Local $cc = "" ; envoi copie

    ; envoie le mail avec outlook
    $oOApp = ObjCreate("Outlook.Application")
    $oOMail = $oOApp.CreateItem ($olMailItem)
    $oOMail.Save
    With $oOMail
        .To = ($mailto)
        .cc = ($cc)
        .Subject = $objet
        .BodyFormat = $olFormatHTML
        .Importance = $olImportanceNormal
        .HTMLBody = "Essai"
        .Send
    EndWith
    $oOApp=0
                Exit
                               Case $Annuler
                                               Exit

                EndSwitch
WEnd
Avatar du membre
mikell
Spammer !
Spammer !
Messages : 6292
Enregistré le : dim. 29 mai 2011 17:32
Localisation : Deep Cévennes
Status : Hors ligne

Re: joindre un fichier avec Outlook via un script

#2

Message par mikell »

Peut-être réponse ici ...
" L'échec est le fondement de la réussite. " (Lao-Tseu )
" Plus ça rate, plus on a de chances que ça marche " (les Shadoks )
caramen
Niveau 2
Niveau 2
Messages : 20
Enregistré le : mer. 03 juil. 2013 07:22
Status : Hors ligne

Re: joindre un fichier avec Outlook via un script  

#3

Message par caramen »

Avec l'udf joint a ma réponse.

Tu peux utiliser la function :
_OL_Wrapper_SendMail($oOL, $sTo , $sCc , $sBCc , $sSubject , $sBody )
MsgBox(0,"Reporting","Test envoi du mail de reporting en silence.",5)
Global $oOL = _OL_Open() ;Ouvre une instance Outlook.exe
If @error <> 0 Then Exit MsgBox(16, "OutlookUD", "Error connecting to Outlook. @error = " & @error & ", @extended: " & @extended)

;$sTO = InputBox("Mail", "Quelle adresse utiliser pour le test d'envoi de mails SILENCIEUX?", "*@*.com" , "",- 1, -1, 0, 0);Demander une adresse mail ?
$sTO = "...........@.........-.....com" ;Email ?
$sCc = "" ; Copie ?
$sBCc = "" ;Carbone ?
$sSubject = "" ;Objet
 $sBody = "" ;Corps du message
_OL_Wrapper_SendMail($oOL, $sTo , $sCc , $sBCc , $sSubject , $sBody ) ;La syntaxe
 _OL_close ($oOL);Quitte le outlook ouvert pour l'envoi du mail.


Test puis je t'aide :)

Ah et je précise... c'est un envoi de mail en mode silence. tu ne vois pas mais ca envoi bien un mail le cas échéant tu auras un message d'erreur.

Autre oublie : la $Variable optionnel pour l’attache du fichier :
A mettre après $sBody dans la syntaxe
 $sAttachments - Optional: Attachments, separated by ;
Fichiers joints
OutlookEX.au3
(361.6 Kio) Téléchargé 155 fois
Répondre