- Option Explicit
-
- Private Declare Function ShellExecute Lib "shell32.dll" _
- Alias "ShellExecuteA" (ByVal hwnd As Long, _
- ByVal lpOperation As String, ByVal lpFile As String, _
- ByVal lpParameters As String, ByVal lpDirectory _
- As String, ByVal nShowCmd As Long) As Long
-
- Private Const SW_SHOWNORMAL = 1
-
- Public Sub SendMail(Optional Address As String, _
- Optional Subject As String, Optional Body As String, _
- Optional CC As String, Optional BCC As String)
-
- Dim strCommand As String
-
- 'Construction du message
- 'Sujet du message
- If Len(Subject) Then strCommand = "&Subject=" & Subject
- 'Corps du message
- If Len(Body) Then strCommand = strCommand & "&Body=" & Body
- 'Copie du message (adresse email attendue)
- If Len(CC) Then strCommand = strCommand & "&CC=" & CC
- 'Copie cachée du message
- If Len(BCC) Then strCommand = strCommand & "&BCC=" & BCC
-
- 'Ajout de l'adresse email à la ligne de commande
- strCommand = "mailto:" & Address & strCommand
-
- 'Execution de la commande via l'API
- Call ShellExecute(Me.hwnd, "open", strCommand, _
- vbNullString, vbNullString, SW_SHOWNORMAL)
-
- End Sub
-
- 'Bouton de commande pour déclencher l'envoi du mail
- Private Sub Command1_Click()
- SendMail "email", "sujet", "message", "copie", "copie cachée"
- End Sub
-
Option Explicit
Private Declare Function ShellExecute Lib "shell32.dll" _
Alias "ShellExecuteA" (ByVal hwnd As Long, _
ByVal lpOperation As String, ByVal lpFile As String, _
ByVal lpParameters As String, ByVal lpDirectory _
As String, ByVal nShowCmd As Long) As Long
Private Const SW_SHOWNORMAL = 1
Public Sub SendMail(Optional Address As String, _
Optional Subject As String, Optional Body As String, _
Optional CC As String, Optional BCC As String)
Dim strCommand As String
'Construction du message
'Sujet du message
If Len(Subject) Then strCommand = "&Subject=" & Subject
'Corps du message
If Len(Body) Then strCommand = strCommand & "&Body=" & Body
'Copie du message (adresse email attendue)
If Len(CC) Then strCommand = strCommand & "&CC=" & CC
'Copie cachée du message
If Len(BCC) Then strCommand = strCommand & "&BCC=" & BCC
'Ajout de l'adresse email à la ligne de commande
strCommand = "mailto:" & Address & strCommand
'Execution de la commande via l'API
Call ShellExecute(Me.hwnd, "open", strCommand, _
vbNullString, vbNullString, SW_SHOWNORMAL)
End Sub
'Bouton de commande pour déclencher l'envoi du mail
Private Sub Command1_Click()
SendMail "email", "sujet", "message", "copie", "copie cachée"
End Sub