Delboy
asked on
Adding a post to an Outlook Folder via VB application
Hi Gang, can anyone tell me how to add a post item to a folder in my Outlook folder list from my VB application.. Thanks.
Derek.
Derek.
ASKER
Hi, I dont want to add a folder, I need to add a post item into an existing folder.
Thanks, Derek.
Thanks, Derek.
ASKER
Hi, I dont want to add a folder, I need to add a post item into an existing folder.
Thanks, Derek.
Thanks, Derek.
ASKER
Hi, I dont want to add a folder, I need to add a post item into an existing folder.
Thanks, Derek.
Thanks, Derek.
Private Sub Command1_Click()
Dim outl As Outlook.Application
Dim outNmsp As Outlook.NameSpace
Dim outFolder As Outlook.MAPIFolder
Dim outMail As Outlook.MailItem
Dim outMovedMail As Outlook.MailItem
Set outl = New Outlook.Application
Set outNmsp = outl.GetNamespace("Mapi")
Set outFolder = outNmsp.GetDefaultFolder(o lFolderInb ox)
Set outMail = outFolder.Items.Add(olMail Item) 'add a newmail item
outMail.Subject = "Hello from Vb" 'subject
outMail.Body = "Yes, this is a new mail from vb!"
'*********
'uncomment this one if you want to make some tricks...
'outMail.SentOnBehalfOfNam e = "Would you like ah?!"
'**********
outMail.Save 'this will save it to the default for this kind of object, wich is not the inbox folder!
'now, move it where you want:
'you have to pass a folder to this method and...
'...to instantiate a new mailitem!
Set outMovedMail = outMail.Move(outFolder)
'now free memory
outMovedMail.Close olDiscard 'you already saved!
Set outMovedMail = Nothing
Set outMail = Nothing
Set outFolder = Nothing
Set outNmsp = Nothing
'depending on you wanting to keep alive outlook, you may skip the folowing
outl.Quit
'but you will have to do this one!
Set outl = Nothing
End Sub
Dim outl As Outlook.Application
Dim outNmsp As Outlook.NameSpace
Dim outFolder As Outlook.MAPIFolder
Dim outMail As Outlook.MailItem
Dim outMovedMail As Outlook.MailItem
Set outl = New Outlook.Application
Set outNmsp = outl.GetNamespace("Mapi")
Set outFolder = outNmsp.GetDefaultFolder(o
Set outMail = outFolder.Items.Add(olMail
outMail.Subject = "Hello from Vb" 'subject
outMail.Body = "Yes, this is a new mail from vb!"
'*********
'uncomment this one if you want to make some tricks...
'outMail.SentOnBehalfOfNam
'**********
outMail.Save 'this will save it to the default for this kind of object, wich is not the inbox folder!
'now, move it where you want:
'you have to pass a folder to this method and...
'...to instantiate a new mailitem!
Set outMovedMail = outMail.Move(outFolder)
'now free memory
outMovedMail.Close olDiscard 'you already saved!
Set outMovedMail = Nothing
Set outMail = Nothing
Set outFolder = Nothing
Set outNmsp = Nothing
'depending on you wanting to keep alive outlook, you may skip the folowing
outl.Quit
'but you will have to do this one!
Set outl = Nothing
End Sub
ASKER
Hi, sorry.. you are telling me how to send a mail from VB application. I need to save a post item into a folder in my outlook folder list.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
My appologies.. I need glasses. Thanks, Derek.
LOL:
>My appologies.. I need glasses. Thanks, Derek
...I am Cesare not Derek...(unless Derek is your name)
;-)
Have a nice day,
Cesare I.
>My appologies.. I need glasses. Thanks, Derek
...I am Cesare not Derek...(unless Derek is your name)
;-)
Have a nice day,
Cesare I.
Dim olookApp As Outlook.Application
Dim olookSpace As Outlook.NameSpace
Dim olookInbox As Outlook.MAPIFolder
Dim olookFolder As Outlook.MAPIFolder
Set olookApp = CreateObject("Outlook.Appl
Set olookSpace = olookApp.GetNamespace("MAP
'Must reference the folder we wish to create the new folder in.
Set olookInbox = olookSpace.GetDefaultFolde
'Use the Add method of the Folders collection of the MAPIFolder
'object returned in the above statement.
Set olookFolder = olookInbox.Folders.Add("My
Set olookFolder = Nothing
Set olookInbox = Nothing
Set olookSpace = Nothing
Set olookApp = Nothing
End Sub
function to add a folder to outlook