Page 1 sur 1

joindre un fichier avec Outlook via un script

Posté : lun. 15 oct. 2018 11:31
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

Re: joindre un fichier avec Outlook via un script

Posté : mar. 16 oct. 2018 14:27
par mikell
Peut-être réponse ici ...

Re: joindre un fichier avec Outlook via un script  

Posté : jeu. 18 oct. 2018 18:09
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 ;