Accueil > > > CONTRÔLER OUTLOOK (1) - ENVOYER UN MAIL DEPUIS VB
CONTRÔLER OUTLOOK (1) - ENVOYER UN MAIL DEPUIS VB
Information sur la source
Description
voici un code, fourni par microsoft, qui vous permet d'envoyer un mail par l'intermédiaire d'outlook depuis votre appli. n'oubliez pas d'ajouter une référence à outlook dans votre appli.
Source
- Function CreateMail(astrRecip As Variant, _
- strSubject As String, _
- strMessage As String, _
- Optional astrAttachments As Variant) As Boolean
-
- Dim olApp As Outlook.Application
- Dim objNewMail As Outlook.MailItem
- Dim varRecip As Variant
- Dim varAttach As Variant
- Dim blnResolveSuccess As Boolean
-
- On Error GoTo CreateMail_Err
-
- Set olApp = New Outlook.Application
- Set objNewMail = olApp.CreateItem(olMailItem)
-
- With objNewMail
- ' Add each item in the varRecip array to the Recipients collection.
- For Each varRecip In astrRecip
- .Recipients.Add varRecip
- Next varRecip
-
- ' Determine if all recipients have corresponding entries in the
- ' Outlook address book.
- blnResolveSuccess = .Recipients.ResolveAll
-
- ' Add each item in the varAttach array to the Attachments collection
- ' and specify the subject and text of the mail message.
- For Each varAttach In astrAttachments
- .Attachments.Add varAttach
- Next varAttach
- .Subject = strSubject
- .Body = strMessage
-
- ' If all recipients are valid then send the message now, otherwise
- ' display the message so the user can fix invalid e-mail addresses.
- If blnResolveSuccess Then
- .Send
- Else
- MsgBox "Unable to resolve all recipients. Please check " _
- & "the names."
- .Display
- End If
- End With
-
- CreateMail = True
-
- CreateMail_End:
- Exit Function
- CreateMail_Err:
- CreateMail = False
- Resume CreateMail_End
- End Function
-
-
Function CreateMail(astrRecip As Variant, _
strSubject As String, _
strMessage As String, _
Optional astrAttachments As Variant) As Boolean
Dim olApp As Outlook.Application
Dim objNewMail As Outlook.MailItem
Dim varRecip As Variant
Dim varAttach As Variant
Dim blnResolveSuccess As Boolean
On Error GoTo CreateMail_Err
Set olApp = New Outlook.Application
Set objNewMail = olApp.CreateItem(olMailItem)
With objNewMail
' Add each item in the varRecip array to the Recipients collection.
For Each varRecip In astrRecip
.Recipients.Add varRecip
Next varRecip
' Determine if all recipients have corresponding entries in the
' Outlook address book.
blnResolveSuccess = .Recipients.ResolveAll
' Add each item in the varAttach array to the Attachments collection
' and specify the subject and text of the mail message.
For Each varAttach In astrAttachments
.Attachments.Add varAttach
Next varAttach
.Subject = strSubject
.Body = strMessage
' If all recipients are valid then send the message now, otherwise
' display the message so the user can fix invalid e-mail addresses.
If blnResolveSuccess Then
.Send
Else
MsgBox "Unable to resolve all recipients. Please check " _
& "the names."
.Display
End If
End With
CreateMail = True
CreateMail_End:
Exit Function
CreateMail_Err:
CreateMail = False
Resume CreateMail_End
End Function
Conclusion
la propriété astrrecip désigne le nom du recipient (destinataire) INSCRIT dans le carnet d'adresse outlook. je vais bientot ajouter une source pour montrer comment manipuler le carnet d'adresse outlook
Sources du même auteur
Sources de la même categorie
Commentaires et avis
Discussions en rapport avec ce code source dans le forum
Envoyer un email via VBA [ par Appolon ]
Bonjour,Voici mon code:Dim myOlApp As New Outlook.ApplicationDim myItem As Outlook.MailItemSet myItem = myOlApp.CreateItem(olMailItem)'tu crée l'objet
Envoyer un email via VBA [HELP] [ par Appolon ]
Bonsoir,Voici mon code:Dim myOlApp As New Outlook.ApplicationDim myItem As Outlook.MailItemSet myItem = myOlApp.CreateItem(olMailItem)'tu crée l'objet
Envoyer un mail avec vba sans passer par outlook si possible [ par Tsunami_11 ]
helloJ aimerais que pour une certaine condition definie sous excel ca envoye un mail a une adresse donnée l'ideal ca serait de le faire sans passer pa
Envoyer un mail à partir d'Access97 [ par Progsam ]
Je cherche a envoyer un mail a partird'access97 via outlook express.Il est possible de le faire avec outlook en declarant une variable outlook.applica
Envoyer un mail sans Winsock ni Outlook ! [ par Jonef ]
Bonjour à tous !Voilà, en fait je souhaite faire un programme qui envois des e-mails, le problème c'est que Winsock ne marche pas donc pas possible d'
Mail anonyme [ par Apophis ]
slt,Comment faire pour envoyer un mail de manière autonome de préférence (sans outlook) ou l'on peut mettre le nom que l'on veut? (le code présent sur
Envoyer un mail sans passer par outlook [ par Chenzen ]
Salut, ca fait 2 semaines que j'essaie de trouver un code pour envoyer un mail depuis mon prog sans passer par outlook mais directement par un serveur
envoi de Mail par Outlook avec VB [ par EvilGost ]
j'arrive à envoyer un mail à partir d'un prog en Visual Basic, mais uniquement avec OutLook 2002 d'installé. Est-il possible d'envoyer un mail par un
[outlook] envoyer un mail par un compte autre que le compte par defaut [ par hfrBelgarion ]
Bon alors voila j explique mon probleme je souhaite envoyer des mail depuis access en utilisant du vba pour l envoiyer a outlook 2000 jusque la pas de
envoyer un mail à partir de outlook express sur Access97 [ par cat25 ]
Bonjour!j'aimerai envoyer des mails en pièce jointe dans une base de donné Access97 sur Outlook expressj'ai essayé ce code DoCmd.SendObject [typeobjet
|
Derniers Blogs
XNA IS DEAD!XNA IS DEAD! par richardc
Depuis la semaine dernière (et grâce aux TechDays 2012), je me penche activement sur la nouvelle version de Windows, aka Windows 8. Vous me direz, il était temps puisque la première preview date de Septembre dernier.
OK. Remarquez, on n'en est qu'aux...
Cliquez pour lire la suite de l'article par richardc TECHDAYS PARIS 2012 : WINDOWS SERVER "8" QUOI DE 9 !TECHDAYS PARIS 2012 : WINDOWS SERVER "8" QUOI DE 9 ! par ROMELARD Fabrice
Speakers: Fabrice Meillon et Stanislas Quastana Cette session est basée entièrement sur celle donnée lors de la BUILD cet hiver. Il n'y a pas d'ajout d'information en rapport avec cet évènement passé. Windows 8 Server sera intégralem...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice [HTML5] AUTOUR DU W3C : NOUVEAUX STANDARDS ET WEB MOBILE (LILLE)[HTML5] AUTOUR DU W3C : NOUVEAUX STANDARDS ET WEB MOBILE (LILLE) par Gio
Je m'y prends un peu tard je sais, mais bon je suis développeur web et donc hyper fainéant ! Toujours dans le cadre des technologies émergentes, ici HTML5, parce qu'on aime HTML5 chez Wyg , nous seront présent, le vieux ( Aurélien V.) et moi, pour pr...
Cliquez pour lire la suite de l'article par Gio [WP7] DYNAMICALLY CHANGE STARTUP PAGE[WP7] DYNAMICALLY CHANGE STARTUP PAGE par KooKiz
Let's say that you want to allow the user to customize the startup page of your application. You can easily change the startup page by editing the 'NavigationPage' attribute in the manifest file. But the manifest cannot be modified once the applicatio...
Cliquez pour lire la suite de l'article par KooKiz
Logiciels
DocTranslate (V3.1.0.0)DOCTRANSLATE (V3.1.0.0)DocTranslate est un traducteur de document Microsoft Word, PowerPoint et Excel. Il permet d'autom... Cliquez pour télécharger DocTranslate Tribler (2012)TRIBLER (2012)Tribler est un client pair à pair (P2P/Peer-to-Peer) open source avec la capacité de regarder des... Cliquez pour télécharger Tribler OneSwarm (2012)ONESWARM (2012)Le peer-to-peer qui protège votre vie privée, c'est OneSwarm.
Ce logiciel de peer-to-peer crypté... Cliquez pour télécharger OneSwarm PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V8.4)PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V8.4)PONAMEDIA TV DEVIENS HELLLOOO FLASH
LA TV SUR VOTRE ORDINATEUR.
Toute une plateforme Multi... Cliquez pour télécharger PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO Academy System (17.2.1.0)ACADEMY SYSTEM (17.2.1.0)Logiciel de gestion des établissements.
- élèves/étudiants (inscription, dossier, absence...)
-... Cliquez pour télécharger Academy System
|