|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Saving outlook email attachment?Public Sub GetAttachments()
' Declare variables Dim ns As [NameSpace] Dim Inbox As MAPIFolder Dim Item As MailItem Dim SubFolder As MAPIFolder Dim Atmt As Attachment Dim FileName As String Dim olApp As Application Dim myRecipient As Recipient olApp = CreateObject("Outlook.Application") ns = olApp.GetNamespace("MAPI") ' Set myRecipient =outlook ns.CreateRecipient("help") 'myRecipient.Resolve Inbox = ns.GetDefaultFolder(OlDefaultFolders.olFolderInbox) SubFolder = Inbox.Folders("Inbox") ' Check Inbox for messages and exit of none found If SubFolder.Items.Count = 0 Then Exit Sub End If ' Check each message for attachments For Each Item In SubFolder.Items ' Save attachments found For Each Atmt In Item.Attachments FileName = "h:\Email Attachments\" & Atmt.FileName Atmt.SaveAsFile(FileName) End If Next Atmt End If Next Item Atmt = Nothing Item = Nothing ns = Nothing End Sub c_shah wrote: Show quoteHide quote > how to save outlook email attachments using VB.net? I am getting compilation error
this is my code Imports Outlook = Microsoft.Office.Interop.Outlook ' Create Outlook Application. Dim objApp As Outlook.Application = New Outlook.Application 'Get Mapi NameSpace Dim objNS As Outlook.NameSpace = objApp.GetNamespace("MAPI") ' Get Messages collection of Inbox. Dim objInbox As Outlook.MAPIFolder = objNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox) Dim objItems As Outlook.Items = objInbox.Items ' Get unread e-mail messages. objItems = objItems.Restrict("[Unread] = true") Dim item As Outlook.MailItem Dim i As Integer 'Dim Item As Object For i = 1 To objItems.Count ' MessageBox.Show(objItems.Item(i).Subject) ' MessageBox.Show(objItems.Item(i).Body) Dim objAttachment As Outlook.Attachment For Each objAttachment In objItems.Item(i) Dim filename As String filename = "C:\Temp\" + objAttachment.FileName objAttachment.SaveAsFile(filename) Next objAttachment Next C_shah,
>I am getting compilation error this is my code Probably you did not set a reference or something like that.> Cor It is working now.
Here is my complete code I am getting a security warning from outlook "a program is trying to access email address from outlook" how to get rid of that message? Also, instead of "Unread items" from the inbox I would like to use selected(highlighted) items from the inbox any way to do this Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ' Create Outlook Application. Dim objApp As Outlook.Application = New Outlook.Application 'Get Mapi NameSpace Dim objNS As Outlook.NameSpace = objApp.GetNamespace("MAPI") objNS.Logon("GA\Cshah", Missing.Value, False, True) ' Get Messages collection of Inbox. Dim objInbox As Outlook.MAPIFolder = objNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox) Dim objItems As Outlook.Items = objInbox.Items ' Get unread e-mail messages. (Collection) objItems = objItems.Restrict("[UnRead] = true") ' objItems = objItems.Restrict( 'Mail Item Dim oMsg As Outlook.MailItem For Each oMsg In objItems Dim objAttachment As Outlook.Attachment For Each objAttachment In oMsg.Attachments Dim filename As String filename = "C:\Temp\" + objAttachment.FileName objAttachment.SaveAsFile(filename) Next objAttachment Next Label1.Text = "Attachments are saved" End Sub C_Shah,
Have a look in this thread there is no 1 to 1 answer, so maybe you find it in there. http://groups.google.com/group/microsoft.public.dotnet.languages.vb/browse_frm/thread/507e83e2fd19337c/15a6683ae027bb23#15a6683ae027bb23 I hope this helps, Cor Show quoteHide quote "c_shah" <shah.chi***@netzero.net> schreef in bericht news:1146062168.533079.199590@g10g2000cwb.googlegroups.com... > It is working now. > Here is my complete code > > I am getting a security warning from outlook "a program is trying to > access email address from outlook" how to get rid of that message? > > Also, instead of "Unread items" from the inbox I would like to use > selected(highlighted) items from the inbox any way to do this > > Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As > System.EventArgs) Handles MyBase.Load > > > ' Create Outlook Application. > Dim objApp As Outlook.Application = New Outlook.Application > > 'Get Mapi NameSpace > Dim objNS As Outlook.NameSpace = objApp.GetNamespace("MAPI") > > objNS.Logon("GA\Cshah", Missing.Value, False, True) > > ' Get Messages collection of Inbox. > Dim objInbox As Outlook.MAPIFolder = > objNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox) > Dim objItems As Outlook.Items = objInbox.Items > > ' Get unread e-mail messages. (Collection) > objItems = objItems.Restrict("[UnRead] = true") > > ' objItems = objItems.Restrict( > > 'Mail Item > Dim oMsg As Outlook.MailItem > > For Each oMsg In objItems > > Dim objAttachment As Outlook.Attachment > For Each objAttachment In oMsg.Attachments > > Dim filename As String > filename = "C:\Temp\" + objAttachment.FileName > objAttachment.SaveAsFile(filename) > Next objAttachment > > > Next > > Label1.Text = "Attachments are saved" > End Sub > Thank you Cor.
Also, anyone know a property that exposes currently selected emails from the outlook? So instead of "Unread items" from the inbox I would like to read selected(highlighted) items from the inbox
"Send To Mail Recipient"
position in array using a string Error Handling: load text file into TextBox Recursion with a Tree View and checkboxes GetType question Missing DataGrid RTF and word tables Associate value with item in combobox Click-Once Deployment of DLLs Automatically interacting with a search engine... |
|||||||||||||||||||||||