forwarding a mail from a particular folder
Hi ,
I am developing an application,that needs me to list down all the mails in a
particular folder under INBOX folder say folder -xxx,the user must be able to
forward that particular item to any user.I am able to get all the mails from the INBOX using MAPI but i am not able to fetch it from the specified folder under INBOX. Please advice any example codes would be of great help.
Thanks ,
Khader
Re: forwarding a mail from a particular folder
Are you doing this in VB or Outlook VBA?
Re: forwarding a mail from a particular folder
How are you getting all the desired emails using mapi if you can not get the items? :confused: Are you using Outlook Object Model or VB's MAPI control?
Re: forwarding a mail from a particular folder
Hi Guys ,
Thanks for the response.See Currently i am using the MAPI to fetch all the mails from the inbox ,I am able to perform all the required funtions on them.
but the trouble is i want to fetch and do similar actions on the mail items from other folders too which are under the inbox.I tried using the outlook objects here to navigate thru the folders ,I am able to open the mail but i want to forward them .Hope this is makes the case clear.
Thanks ,
Khader
Re: forwarding a mail from a particular folder
Re: forwarding a mail from a particular folder
Show us the code you are using now.
Re: forwarding a mail from a particular folder
So this is specifically for your Outlook and not for other systems?
If you create a search folder you could select all the found mail items and just forward them. Also, are you forwarding the emails to just one email arress or all different ones? Do you want to use the MAPI control or the Outook Object model?
Re: forwarding a mail from a particular folder
Hi Robbdog and HACK,
This is something that i used to move to a folder named "CAIT" ,I am also not sure how to declare myitems here.
VB Code:
Dim dosNameSpace As Outlook.NameSpace
Dim dosPublics As MAPIFolder
Dim myfolder As MAPIFolder
Set dosNameSpace = Application.GetNamespace("MAPI")
Set dosPublics = dosNameSpace.GetDefaultFolder(olFolderInbox) 'should be the public
Set myfolder = dosPublics.Folders("CAIT")
Set myitems = myfolder.Items
myitems(2).display
The following is my MAPI code that i use to fetch the mails and forward them
This is to fetch the mails from inbox to a flexgrid....
VB Code:
Private Sub Command2_Click()
'MAPISession1.SignOn
'MAPIMessages1.SessionID = MAPISession1.SessionID
MAPIMessages1.Fetch
For i = 0 To MAPIMessages1.MsgCount - 1
j = i + 1
flxinb.Rows = flxinb.Rows + 1
MAPIMessages1.MsgIndex = i
flxinb.Row = j
flxinb.Col = 0
flxinb.Text = MAPIMessages1.MsgOrigDisplayName
flxinb.Row = j
flxinb.Col = 1
flxinb.Text = MAPIMessages1.MsgSubject
flxinb.Row = j
flxinb.Col = 2
flxinb.Text = MAPIMessages1.MsgDateReceived
Next i
'MAPISession1.SignOff
End Sub
this is to forward ..
VB Code:
Private Sub cmdsnd_Click()
If rdfrw.Value = True Then
With MAPIMessages1
.Fetch
.MsgIndex = flxinb.Row - 1
.Forward
.MsgSubject = "Ticket ID"
.Show
.MsgNoteText = "Hi Bo /Note this following forwareded message"
MAPIMessages1.Send True
End With
Else
MsgBox "Please Select request type ", vbOKOnly, "ARM Ver 1.3"
End If
End Sub
While forwarding I also wanna use display the original message along with the new text .
Can you guys advice me on both my problem
1) To forward a mail from a particular folder under inbox by searching the subject line to any user.
2) To append the forwarded mail instead of over writing it.
Thanks and Regards,
Khader
Edit: Added [vbcode][/vbcode] tags for clarity and removed email address from post to protect member from possible spammers - Hack
Re: forwarding a mail from a particular folder
Looks like your using both the vb6 mapi control and the outlook object model. There is no need to use both. If you have Outlook and this is just for you then its easier to just use Outlook.
VB Code:
Option Explicit
'Add a reference to MS Outlook xx.0 Object Library
Private moApp As Outlook.Application
Private Sub Command1_Click()
Dim oInbox As Outlook.MAPIFolder
Dim i As Integer
Set oInbox = moApp.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox)
For i = 1 To oInbox.Items.Count
flxinb.Row = i
flxinb.Col = 0
flxinb.Text = oInbox.Items.Item(i).Subject
flxinb.Row = i
flxinb.Col = 1
flxinb.Text = oInbox.Items.Item(i).SenderName
flxinb.Row = i
flxinb.Col = 2
flxinb.Text = oInbox.Items.Item(i).ReceivedTime
Next
Set oInbox = Nothing
End Sub
Private Sub Form_Load()
Set moApp = New Outlook.Application
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
moApp.Quit
Set moApp = Nothing
End Sub
Re: forwarding a mail from a particular folder
Hi RobDog,
I accept to the fact that we can use any one of either MAPI or outlook,
But my problem is that i need to forward mail and perform all functions on a particular mail that is present in a particular folder using a subject line search that is under INBOX .
hope i am clear
Khader
Re: forwarding a mail from a particular folder
Just do a loop checking the subject property. Then when found set a Mailitem object variable to that item and .Forward
VB Code:
If oInbox.Items.Item(i).Subject = "RE: Something" Then
Set oMsg = oInbox.Items.Item(i)
oMsg.Forward
oMsg.Send
End If
Check Outlooks help file for more info on the Fordward method. My code example is only detailed pseudocode.
Moved from Classic VB forum.
Re: forwarding a mail from a particular folder
Hi RobDog,
Perfect Thanks a lot buddy will try that out ..Thanks a lot for all your help.