Envoi EMail Type avec valeur afichées dans Userform
Bonjour le Forum,
Me voici face à un nouveau problème :
J’ai créé une UserFormEMail dans laquelle on retrouve :
- 2 dates (TextBox11 et TextBox12)
- 1 nom (ComboBox1)
- 1 prenom (TextBox1)
- 1 e-mail (TextBox2)
- 1 numero projet (ComboBox3)
- 3 boutons d’options (OptionButton1, OptionButton2, OptionButton3) dans un Frame5
- 1 bouton « Envoyer »
J’ai réussi à charger les ComboBox et les ListBox
Est-il possible, lorsque j’ai sélectionné un bouton option (par exemple OptionButton1) et que je clique sur le bouton « Envoyer » que ma messagerie retourne un mail type avec comme destinataire : L’adresse mail affichée dans la « Textbox2 » du style :
Titre :
« Suivi projet »
Contenu message :
« Bonjour Monsieur *valeur affichée dans ComboBox1*,
Concernant le projet : *valeur affichée dans Combobox3* qui a commencer le *valeur affichée dans TextBox10* nous avons bien pris en compte votre demande »
La messagerie que j’utilise est « Lotus Notes 6.5 » et s’exécute par défaut directement si je clique sur une adresse mail présente sur ma feuille de calcul.
Je m’améliore petit à petit mais je n’ai encore jamais rencontré ces fonctions.
Auriez-vous une idée de comment faire ?
Merci pour votre aide.
Bruno.
Salut le forum
Tu peux commencer par etudier ceci, tu reviens en suite pour adapter si des problèmes.
Pour envoyer un E-mail : Envoyer E-mail sans Outlook
Mytå
Bonjour le Forum.
J'ai essayé de faire mon possible mais jamais il ne m'a ouvert ma messagerie.
Soit il bug au .send, soit si je l'enleve il ne se passe rien.
pour l'instant même un simple envoie de message indépendament du contenu, je n'y arrive pas.
Dans une feuille Excel, si dans une cellule je rentre une adresse Mail, et que je clique dessus, ma messagerie s'ouvre en affichant automatiquement le destinataire.
Peut-être puis-je extraire l'adresse mail se trouvant dans ma TextBox1, la copier dans une cellule et provoquer un clic automatiquement sur cette même cellule pour ouvrir la messagerie. Et une fois la messagerie ouverte, faire une macro pour y mettre un message dedans.
Je n'ai aucune idée de la bonne méthode à utiliser.
Merci pour vos réponses.
Cordialement Bruno
Re le forum
Je ne dispose pas de Lotus Notes, alors je te laisse faire les essais.
On va commencer par ajouter la référence à Lotus Notes
- Depuis VBA, Outils --> Références --> Cocher 'Lotus Notes Automation Classes".
Et ensuite le code VBA
Sub Send_Email_via_Lotus_Notes()
Dim Maildb As Object
Dim MailDoc As Object
Dim Body As Object
Dim Session As Object
'Start a session of Lotus Notes
Set Session = CreateObject("Lotus.NotesSession")
'This line prompts for password of current ID noted in Notes.INI
Call Session.Initialize
'or use below to provide password of the current ID (to avoid Password prompt)
'Call Session.Initialize("<password>")
'Open the Mail Database of your Lotus Notes
Set Maildb = Session.GETDATABASE("", "D:\Notes\data\Mail\eXceLiTems.nsf")
If Not Maildb.IsOpen = True Then Call Maildb.Open
'Create the Mail Document
Set MailDoc = Maildb.CREATEDOCUMENT
Call MailDoc.REPLACEITEMVALUE("Form", "Memo")
'Set the Recipient of the mail
Call MailDoc.REPLACEITEMVALUE("SendTo", "Ashish Jain")
'Set subject of the mail
Call MailDoc.REPLACEITEMVALUE("Subject", "Subject Text")
'Create and set the Body content of the mail
Set Body = MailDoc.CREATERICHTEXTITEM("Body")
Call Body.APPENDTEXT("Body text here")
'Example to create an attachment (optional)
Call Body.ADDNEWLINE(2)
Call Body.EMBEDOBJECT(1454, "", "C:\dummy.txt", "Attachment")
'Example to save the message (optional) in Sent items
MailDoc.SAVEMESSAGEONSEND = True
'Send the document
'Gets the mail to appear in the Sent items folder
Call MailDoc.REPLACEITEMVALUE("PostedDate", Now())
Call MailDoc.SEND(False)
'Clean Up the Object variables - Recover memory
Set Maildb = Nothing
Set MailDoc = Nothing
Set Body = Nothing
Set Session = Nothing
End SubMytå
Référence : http://www.excelitems.com
Merci je regarde ça ce week-end et je te tiens au courant!
Bon weekend! Bruno
Bonjour, après mes recherches, voici le code auquel j'arrive qui effectue à peu pres la fonction que je souhaite.
Private Sub CommandButton1_Click()
'Set up the objects required for Automation into lotus notes
Dim Maildb As Object 'The mail database
Dim UserName As String 'The current users notes name
Dim MailDbName As String 'THe current users notes mail database name
Dim MailDoc As Object 'The mail document itself
Dim AttachME As Object 'The attachment richtextfile object
Dim Session As Object 'The notes session
Dim EmbedObj As Object 'The embedded object (Attachment)
If UserFormEMail.ListBox2.ListCount = 0 Then MsgBox "No Hay Proyectos Seleccionados Para Mensaje"
If UserFormEMail.ListBox2.ListCount = 0 Then Exit Sub
'Start a session to notes
Set Session = CreateObject("Notes.NotesSession")
'Get the sessions username and then calculate the mail file name
'You may or may not need this as for MailDBname with some systems you
'can pass an empty string
UserName = Session.UserName
MailDbName = Left$(UserName, 1) & Right$(UserName, (Len(UserName) - InStr(1, UserName, " "))) & ".nsf"
'Open the mail database in notes
Set Maildb = Session.GETDATABASE("", MailDbName)
If Maildb.IsOpen = True Then
'Already open for mail
Else
Maildb.OPENMAIL
End If
'Set up the new mail document
Set MailDoc = Maildb.CREATEDOCUMENT
MailDoc.Form = "Memo"
MailDoc.Sendto = "CST_BAntoniol@xxxxxx.com" 'UserFormEMail.TextBox9.Value
MailDoc.CopyTo = ""
MailDoc.Subject = "essaie d'envoi adresse differentes"
' Construction du corps du message
Set objNotesField = MailDoc.CreateRichTextItem("Body")
With objNotesField
.AppendText "Buenos Dias,"
.AddNewline 2
.AppendText "Usted podrìa enviarme el Order Entry Form del (de los) proyecto(s) sigienete(s):"
.AddNewline 2
For i = 0 To UserFormEMail.ListBox2.ListCount - 1
.AppendText UserFormEMail.ListBox2.List(i) & " --- " & UserFormEMail.ListBox3.List(i)
.AddNewline 2
Next i
.AddNewline 2
.AppendText "Un saludo Cordial"
.AddNewline 1
.AppendText "Bruno Antoniol"
.AddNewline 3
End With
MailDoc.SaveMessageOnSend = True
'Set up the embedded object and attachment and attach it
'Send the document
MailDoc.PostedDate = Now() 'Gets the mail to appear in the sent items folder
MailDoc.Send 0, Recipient
'Clean Up
Set Maildb = Nothing
Set MailDoc = Nothing
Set AttachME = Nothing
Set Session = Nothing
Set EmbedObj = Nothing
End SubMon probleme est que cette commande envoie le mail directement.
aurriez vous un moyen d'afficher le message avant de l'envoyer pour effectuer les dernières modifications si besoin est?
Merci, Cdt
Bruno
Voici mon code final qui je pense adapté correctement pourra servir à d'autres personnes.
'---------- API -----------
'pour faire passer au premier plan
Private Declare Function SetForegroundWindow Lib "user32" (ByVal hWnd As Long) As Long
'pour ouvrir la fenêtre
Private Declare Function ShowWindow Lib "user32" (ByVal hWnd As Long, _
ByVal nCmdShow As Long) As Long
'pour vérifier si Lotus est ouvert
Private Declare Function FindWindow Lib "user32" Alias _
"FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Dim sSrvr As String 'Le serveur de mail de l'utilisateur courant
Dim MailDbName As String 'Le nom de la base mail de l'utilisateur courant
Dim UserName As String 'Le nom de l'utilisateur courant
Dim retVal As Variant 'La valeur de retour de la fonction
'---------------- fonction ouverture de session Notes -----------
Function CreateNotesSession() As Boolean
Const notesclass$ = "NOTES"
Const SW_SHOWMAXIMIZED = 3 'plein ecran
Const SW_SHOWMMINIZED = 2 'reduire
Const SW_SHOWWINDOW = 1 'fenetre
Const SW_SHOW = 5
Dim Lotus_Session As Object
Dim rc&
Dim lotusWindow&
' lotusWindow = FindWindow(notesclass, vbNullString)
' sSrvr = Lotus_Session.GETENVIRONMENTSTRING("MailServer", True)
' MailDbName = Lotus_Session.GETENVIRONMENTSTRING("MailFile", True)
' UserName = Lotus_Session.UserName
' DoEvents
'Ouverture de Lotus Notes
'Mettre votre chemin d'accès pour notes.exe et notes.ini'
'retVal = Shell("C:\Program Files\lotus\notes\notes.exe =C:\Program Files\lotus\notes\notes.ini", vbMaximizedFocus)
'verifier que Lotus est bien ouvert (recupere le handle)
lotusWindow = FindWindow(notesclass, vbNullString)
If lotusWindow <> 0 Then
rc = ShowWindow(lotusWindow, SW_SHOW)
rc = SetForegroundWindow(lotusWindow)
CreateNotesSession = True
Else
CreateNotesSession = False
End If
End Function
Private Sub CommandButton1_Click()
Const EMBED_ATTACHMENT As Integer = 1454
Const EMBED_OBJECT As Integer = 1453
Const EMBED_OBJECTLINK As Integer = 1452
Dim s As Object ' use back end classes to obtain mail database name
Dim db As Object '
Dim doc As Object ' front end document
Dim beDoc As Object ' back end document
Dim workspace As Object ' use front end classes to display to user
Dim bodypart As Object '
Dim bodyAtt As Object '
Dim lbsession As Boolean
lbsession = CreateNotesSession
If lbsession Then
'cree la session Lotus Notes
Set s = CreateObject("Notes.Notessession")
'se connecte a sa database
Set db = s.getDatabase(sSrvr, MailDbName)
If db.IsOpen = True Then
'database deja ouvert
Else
Call db.Openmail
End If
'cree un document memo
Set beDoc = db.CreateDocument
beDoc.Form = "Memo"
'construction du mail
Set bodypart = beDoc.CreateRichTextItem("Body")
'beDoc.From = "Moi" 'inutile
beDoc.SendTo = UserFormEMail.TextBox9.Value
beDoc.CopyTo = CCToAdr
beDoc.BlindCopyTo = BCCToAdr
beDoc.Subject = UserFormEMail.TextBox10.Value & " Pendiente"
With bodypart
.AppendText "Buenos Dias,"
.AddNewline 2
.AppendText "Usted podrìa enviarme el Order Entry Form del (de los) proyecto(s) sigienete(s):"
.AddNewline 2
For i = 0 To UserFormEMail.ListBox2.ListCount - 1
.AppendText UserFormEMail.ListBox2.List(i) & " --- " & UserFormEMail.ListBox3.List(i)
.AddNewline 2
Next i
.AddNewline 2
.AppendText "Un saludo Cordial"
.AddNewline 1
.AppendText "Bruno Antoniol"
.AddNewline 3
End With
'-----------------------------------------
'Remarque s'il y a des destinataires multiples, il suffit de mettre un tableau
'd'e-mail dans SendTo (CopyTo,BlindCopyTo)
'exemple :
'Dim recip(25) as variant
'recip(0) = "emailaddress1"
'recip(1) = "emailaddress2" e.t.c
'beDoc.sendto = recip
'----------------------------------------
' documents joint 1
If Len(Attach1) > 0 Then
If Len(dir(Attach1)) > 0 Then
Set bodyAtt = bodypart.EmbedObject(EMBED_ATTACHMENT, "", Attach1, dir(Attach1))
End If
End If
' documents joint 2
If Len(Attach2) > 0 Then
If Len(dir(Attach2)) > 0 Then
Call bodyAtt.EmbedObject(EMBED_ATTACHMENT, "", Attach2, dir(Attach2))
End If
End If
For i = 0 To UserFormEMail.ListBox2.ListCount - 1
Textei = Textei & ListBox2.List(i) & " --- " & ListBox3.List(i) & Chr(10) & Chr(10)
Next i
'Affichage du mail dans Lotus Notes
Set workspace = CreateObject("Notes.NotesUIWorkspace")
Call workspace.EditDocument(True, beDoc).FieldSetText("Body", "Bonjour Monsieur " & TextBox1 & " " & ComboBox1 & "," & Chr(10) & Chr(10) & _
"Je vous écrit concernant les projets: " & Listei & Chr(10) & Chr(10) & _
"Afin que vous apportiez les précisions suivantes: " & CheckBox1.Caption & _
" avant la date suivante: " & TextBox2 & Chr(10) & Chr(10) & Chr(10) & " Meilleures Salutations.Bruno")
Set s = Nothing
Else
MsgBox "Votre Lotus Notes est fermé !"
End If
End SubCdt et bonne chance si vous utilisez Lotus notes!!
Bruno