| auteur : Etienne Bar |
Pour exécuter ce code il faut la référence : Microsoft Outlook X.0 Object Library
Public Sub CreateEmail ( _
Recipient As String , _
Subject As String , _
Body As String , _
Optional Attach As Variant)
Dim I As Integer
Dim oEmail As Outlook. MailItem
Dim appOutLook As Outlook. Application
Set appOutLook = New Outlook. Application
Set oEmail = appOutLook. CreateItem (olMailItem)
oEmail. To = Recipient
oEmail. Subject = Subject
oEmail. Body = Body
If Not IsMissing (Attach) Then
If TypeName (Attach) = " String " Then
oEmail. Attachments . Add Attach
Else
For I = 0 To UBound (Attach) - 1
oEmail. Attachments . Add Attach (I)
Next
End If
End If
oEmail. Send
Set oEmail = Nothing
Set appOutLook = Nothing
End Sub
|
Et pour éviter la demande d'Outlook qui indique qu'une application est en train d'envoyer un message, il y a une solution ici :
|
lien : Le publipostage avec Access
lien : Comment envoyer un mail format HTML avec Outlook
|
| auteurs : Thierry AIM, Alexandre Lokchine | Ce code n'est à utiliser seulement si Outlook est le client de messagerie par défaut, sinon MAPI vous renvoie une
erreur.
Cochez la référence à Outlook dans les références du projet. Posez un textbox nommé "résultat" sur une form et
placez ce code dans le module de la form :
Private Declare Function MAPIDetails Lib " MAPI32.DLL " Alias " BMAPIDetails " _
(ByVal Session& , ByVal UIParam& , Recipient As MapiRecip, _
ByVal Flags& , ByVal Reserved& ) As Long
Private Declare Function MAPIResolveName Lib " MAPI32.DLL " Alias " BMAPIResolveName " _
(ByVal Session& , ByVal UIParam& , ByVal UserName$, _
ByVal Flags& , ByVal Reserved& , Recipient As MapiRecip) As Long
Private Type MapiRecip
Reserved As Long
RecipClass As Long
Name As String
Address As String
EIDSize As Long
EntryID As String
End Type
Sub listemail ()
Dim X As Long, I As Long
Dim out As Outlook. Application
Dim a As Object, mapi As Object
Dim ctrlists As Integer
Dim info As MapiRecip
Set out = New Outlook. Application
Set mapi = out. GetNameSpace (" MAPI " )
For ctrlists = 1 To mapi. AddressLists . Count
Set a = mapi. AddressLists (ctrlists)
For X = 1 To a. AddressEntries . Count
I = MAPIResolveName (0 , 0 , a. AddressEntries (X), 0 , 0 , info)
resultat. Text = resultat. Text & " Nom : " & info. Name & " " & " @ : " & _
Replace (info. Address , " SMTP: " , " " ) & vbCrLf
DoEvents
Next
DoEvents
Next
Set a = Nothing
Set out = Nothing
Set mapi = Nothing
End Sub
|
La procédure listemail affiche les informations dans le textbox.
|
lien : FAQ VB
|
| auteur : Team Access | Function SendMailCDO (MTo As String , MSubject As String , Optional MBody As String , Optional MAttach As String )
Dim myOlApp As Object
Dim myitem As Object
Set myOlApp = CreateObject (" Outlook.Application " )
Set myitem = myOlApp. CreateItem (0 )
myitem. Body = MBody
myitem. Attachments . Add MAttach
myitem. Subject = MSubject
myitem. To = MTo
myitem. Save
Set myOlApp = Nothing
End Function
|
|
lien : Le publipostage avec Access
|
| auteur : Cafeine |
Pour pouvoir ajouter des enrichissements de mise en forme on peut utiliser du HTML dans le corps du message grâce à .HTMLBody
comme dans la fonction suivante :
Private Sub cmdSend_Click ()
Dim strHTML As String
Dim oEmail As Outlook. MailItem
Dim appOutlook As Outlook. Application
Set appOutlook = New Outlook. Application
Set oEmail = appOutlook. CreateItem (olMailItem)
oEmail. To = Me. txtTo
oEmail. Subject = Me. txtSubject
strHTML = " <!DOCTYPE HTML PUBLIC " " -//W3C//DTD HTML 4.0 Transitional//EN " " > " & _
" <HTML><HEAD> " & _
" <META http-equiv=Content-Type content= " " text/html; charset=iso-8859-1 " " > " & _
" <META content= " " MSHTML 6.00.2800.1516 " " name=GENERATOR></HEAD> " & _
" <BODY><DIV STYLE= " " font-size: 11px; font-face: Tahoma; " " > "
oEmail. HTMLBody = strHTML & Replace (Me. txtBody , vbCrLf , " <br> " ) & " </DIV></BODY></HTML> "
oEmail. Send
Set oEmail = Nothing
Set appOutlook = Nothing
End Sub
|
|
lien : Le publipostage avec Access
|
Consultez les autres F.A.Q's
Les sources présentés sur cette pages sont libre de droits,
et vous pouvez les utiliser à votre convenance. Par contre cette page de présentation de ces sources constitue une oeuvre intellectuelle protégée par les droits d'auteurs.
Copyright ©2004
Developpez LLC. Tout droits réservés Developpez LLC.
Aucune reproduction, même partielle, ne peut être faite de ce site et de
l'ensemble de son contenu : textes, documents et images sans l'autorisation
expresse de Developpez LLC. Sinon vous encourez selon la loi jusqu'à 3 ans
de prison et jusqu'à 300 000 E de dommages et intérets.
Cette page est déposée à la SACD.
|