I am not sure wether my question is fall under ASP or VB but i am looking forward for solution.
I have a machine on which a micorsoft outlook working with exchange server. All emails related to my email address automaticlly download into my PST file. Now I want to run some procedure through which I can copy/move email attachments in one folder programaticlly
with VB.NET.
I have no idea where to start. should i write windows application over Visual Studio or can also create SSIS package with script. What name spaces will be required and how to perform this opration?
plz give any link to article because i have nothing in my mind rightnow.
I got one solution, What I did, I created a macro in outlook 2007. The below procedure scan unread emails in a defined folder and copy attachments on local drive, further mark all unread emails as read. hope this helps to people who are looking for the solution.
[:D]
Sub GetAttachments()
Dim ns As NameSpace
Dim Inbox As MAPIFolder
Dim SubFolder As MAPIFolder
Dim Item As Object
Dim Atmt As Attachment
Dim FileName As String
Dim i As Integer
On Error GoTo GetAttachments_err
Set ns = GetNamespace("MAPI")
Set Inbox = ns.GetDefaultFolder(olFolderInbox)
Set SubFolder = Inbox.Folders("Write-Off Approvals")
i = 0
'Check for items in inbox
If SubFolder.UnReadItemCount = 0 Then
MsgBox "There are no messages in the Write-Off Approvals.", vbInformation, _
"Nothing Found"
Exit Sub
End If
'Scan for attachments
For Each Item In SubFolder.Items
DoEvents
If (Item.UnRead) Then
For Each Atmt In Item.Attachments
FileName = "C:\Email Attachments\" & Atmt.FileName
Atmt.SaveAsFile FileName
i = i + 1
Item.UnRead = False
Next Atmt
End If
Next Item
'Display summary
If i > 0 Then
MsgBox "I found " & i & " attached files." _
& vbCrLf & "I have saved them into the C:\Email Attachments folder." _
& vbCrLf & vbCrLf & "Have a nice day.", vbInformation, "Finished!"
Else
MsgBox "I didn't find any attached files in your mail.", vbInformation, _
"Finished!"
End If
'Clear Memory
GetAttachments_exit:
Set Atmt = Nothing
Set Item = Nothing
Set ns = Nothing
Exit Sub
starlet_gt
Member
11 Points
68 Posts
How to copy/move email attachments from outlook programaticlly
May 08, 2009 09:11 AM|LINK
Hi,
I am not sure wether my question is fall under ASP or VB but i am looking forward for solution.
I have a machine on which a micorsoft outlook working with exchange server. All emails related to my email address automaticlly download into my PST file. Now I want to run some procedure through which I can copy/move email attachments in one folder programaticlly with VB.NET.
I have no idea where to start. should i write windows application over Visual Studio or can also create SSIS package with script. What name spaces will be required and how to perform this opration?
plz give any link to article because i have nothing in my mind rightnow.
Thanks
MIZ
nmreddy83
Contributor
2270 Points
410 Posts
Re: How to copy/move email attachments from outlook programaticlly
May 08, 2009 11:23 AM|LINK
you can use VSTO in .net to play with office applications
UjjwalMeshra...
Participant
1179 Points
293 Posts
Re: How to copy/move email attachments from outlook programaticlly
May 08, 2009 01:53 PM|LINK
hi,
refer this
http://forums.devx.com/showthread.php?t=152716
http://forums.asp.net/p/1041781/1452223.aspx
Regards
ahsanm.m
Contributor
5254 Points
781 Posts
Re: How to copy/move email attachments from outlook programaticlly
May 09, 2009 12:31 PM|LINK
Using Visual Studio 2005/2008-> office programming for solve your problem,
here is some link for your consideration;
http://msdn.microsoft.com/en-us/library/aa289167.aspx
http://www.devnewsgroups.net/group/microsoft.public.office.developer.outlook.vba/topic11414.aspx
http://search.techrepublic.com.com/search/reading+outlook+message.html
DotnetBoss | asp.net boss
starlet_gt
Member
11 Points
68 Posts
Re: How to copy/move email attachments from outlook programaticlly
May 11, 2009 10:23 AM|LINK
I have checked all links above but it come up with no results ...
starlet_gt
Member
11 Points
68 Posts
Re: How to copy/move email attachments from outlook programaticlly
May 12, 2009 04:57 AM|LINK
I got one solution, What I did, I created a macro in outlook 2007. The below procedure scan unread emails in a defined folder and copy attachments on local drive, further mark all unread emails as read. hope this helps to people who are looking for the solution. [:D]
Sub GetAttachments()
Dim ns As NameSpace
Dim Inbox As MAPIFolder
Dim SubFolder As MAPIFolder
Dim Item As Object
Dim Atmt As Attachment
Dim FileName As String
Dim i As Integer
On Error GoTo GetAttachments_err
Set ns = GetNamespace("MAPI")
Set Inbox = ns.GetDefaultFolder(olFolderInbox)
Set SubFolder = Inbox.Folders("Write-Off Approvals")
i = 0
'Check for items in inbox
If SubFolder.UnReadItemCount = 0 Then
MsgBox "There are no messages in the Write-Off Approvals.", vbInformation, _
"Nothing Found"
Exit Sub
End If
'Scan for attachments
For Each Item In SubFolder.Items
DoEvents
If (Item.UnRead) Then
For Each Atmt In Item.Attachments
FileName = "C:\Email Attachments\" & Atmt.FileName
Atmt.SaveAsFile FileName
i = i + 1
Item.UnRead = False
Next Atmt
End If
Next Item
'Display summary
If i > 0 Then
MsgBox "I found " & i & " attached files." _
& vbCrLf & "I have saved them into the C:\Email Attachments folder." _
& vbCrLf & vbCrLf & "Have a nice day.", vbInformation, "Finished!"
Else
MsgBox "I didn't find any attached files in your mail.", vbInformation, _
"Finished!"
End If
'Clear Memory
GetAttachments_exit:
Set Atmt = Nothing
Set Item = Nothing
Set ns = Nothing
Exit Sub
'Error Handler
GetAttachments_err:
MsgBox "An unexpected error has occurred." _
& vbCrLf & "Please note and report the following information." _
& vbCrLf & "Macro Name: GetAttachments" _
& vbCrLf & "Error Number: " & Err.Number _
& vbCrLf & "Error Description: " & Err.Description _
& vbCrLf & "Error Line: " & Err.Source _
, vbCritical, "Error!"
Resume GetAttachments_exit
End Sub