473,320 Members | 1,817 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Email folder import with attachment

11 Byte
Hey guys

I'm trying to import Email folder but I can't find a way to import the attachment as well

Knowing that there is a cell that determines whether there is an attachment or not

So what I need is a code to be associated to a button that can show the attachment(s)
Nov 10 '20 #1
5 3904
jimatqsi
1,271 Expert 1GB
I guess "importing it" implies some preferred destination, which in your case I cannot speak to. But here is how you can save an email attachment. If you want to show it, it will depend on the file type and what tool or program you use to show/open the file.

Here's a slice of code I wrote. I've pulled some selected lines out of a block of code and added the necessary next/ends for this quick reply

Expand|Select|Wrap|Line Numbers
  1.       Dim Folder As Outlook.MAPIFolder
  2.       Dim SubFolder As Outlook.MAPIFolder
  3. 250   For Each Folder In objNSpace.folders
  4. 260       For Each SubFolder In Folder.folders
  5. 270       For Each UserFolder In SubFolder.folders
  6. 280       For Each objItem In UserFolder.Items  '  myFolder.Items
  7. 290           If objItem.Class = olMail Then
  8.                   Dim objMail As Outlook.MailItem
  9. 300               Set objMail = objItem
  10.  
  11. 380               For Each att In objItem.Attachments
  12. 390                   bSkip = False
  13. 400                   If objMail.ReceivedTime <= rsEmail!LastEmailReceived Then
  14. 410                     att.SaveAsFile Path_and_Fname 
  15. 420                   End If
  16.                end if  ' objitem.class=olMail
  17.     next objitem
  18.     next userfolder
  19.     next subfolder
  20.     next folder
  21.  
Nov 10 '20 #2
Lou699
11 Byte
I changed the UserFolder.Items to Inbox.Items however it didn't work

If you can help of how it use the code or where can I assign it to let it work
Nov 11 '20 #3
ADezii
8,834 Expert 8TB
I am also confused as to what you mean by 'Import', but the following Code will:
  1. Create an Instance of Microsoft Outlook.
  2. Access the Default Inbox.
  3. Loop thru every Email in the Inbox.
    1. If the Email contains 1 or more Attachments, Print and sequentially number the Emails to the Immediate Window.
  4. Perform some basic Cleanup Chores.
  5. Obviously, change to suit you specific needs.
  6. Code Definition:
    Expand|Select|Wrap|Line Numbers
    1. 'Must set a Reference to the Microsoft Outlook XX.X Object Library
    2. Dim appOut As Outlook.Application
    3. Dim olNS As Outlook.Namespace
    4. Dim oFldr As Outlook.MAPIFolder
    5. Dim oItem As Outlook.MailItem
    6. Dim oAtch As Outlook.Attachment
    7. Dim intNumOAttch As Integer
    8. Dim intCtr As Integer
    9.  
    10. Set appOut = New Outlook.Application
    11. Set olNS = appOut.GetNamespace("MAPI")
    12. Set oFldr = olNS.GetDefaultFolder(olFolderInbox)
    13.  
    14. For Each oItem In oFldr.Items
    15.   If oItem.Attachments.Count > 0 Then
    16.     Debug.Print oItem.Subject
    17.       For intCtr = 1 To oItem.Attachments.Count
    18.         Debug.Print "  |-- " & Format$(intCtr, "00") & ":  " & oItem.Attachments(intCtr)
    19.       Next
    20.     Debug.Print "---------------------------------------------------------------------------------"
    21.   End If
    22. Next oItem
    23.  
    24. Set oFldr = Nothing
    25. Set olNS = Nothing
    26. Set appOut = Nothing
  7. Sample OUTPUT:
    Expand|Select|Wrap|Line Numbers
    1. Video Project request process
    2.   |-- 01:  Video Production Request Form.pdf
    3.   |-- 02:  Video Edit Request Form.pdf
    4.   |-- 03:  Production Release Form.pdf
    5. --------------------------------------------------
    6. Phone list
    7.   |-- 01:  My Contacts Phone List 19-20.docx
    8. --------------------------------------------------
    9. Vacation Photos (September 2020) 
    10.   |-- 01:  image077.jpg
    11.   |-- 02:  image013.jpg
    12.   |-- 03:  image014.jpg
    13.   |-- 04:  image015.jpg
    14.   |-- 05:  image016.jpg
    15.   |-- 06:  image017.jpg
    16.   |-- 07:  image018.jpg
    17.   |-- 08:  image019.jpg
    18.   |-- 09:  image020.jpg
    19. --------------------------------------------------
    20. FW: RE: Accessibility issues for people who can't wear masks
    21.   |-- 01:  image002.jpg
    22.   |-- 02:  image003.png
    23.   |-- 03:  image004.png
    24.   |-- 04:  image005.png
    25.   |-- 05:  image006.png
    26.   |-- 06:  image007.png
Nov 13 '20 #4
Lou699
11 Byte
Thanks a lot for the reply
What I'm doing is I'm trying to collect emails using ms access, so at the beginning I've used the import from external data option to get the email folder into a table in access and then I created a form to be able to see the email contents, sender ... etc.
However if there is an attachment in the mail I don't know how to preview it within the access form.

adding to this I don't know to what exactly do I assign the code.
Nov 16 '20 #5
ADezii
8,834 Expert 8TB
  1. Save each Attachment to Disk using the SaveAsFile() Method of the Attachment Object
  2. Created a Related Table to your EMail Table that stores the Absolute PATHs to the previously saved Attachments. A Foreign Key in this Table will Link to the EMail Table.
  3. You can create a Sub-Form on you Main Form that will contain the Attachment Information
  4. Using any of several Methods, clicking on an Attachment Record in the Sub-Form will open that Attachment.
Nov 16 '20 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: bruce | last post by:
I can send an email from any client (outlook, lotus notes), and fill it with all sorts of fonts (bold, courier, etc). When the mail is received, the client reads it inline, not as an attachment. ...
0
by: Andrew Chan | last post by:
Dear All, I'm new in VS C++.I would like to write a c++ program that can be send email with attachment,and all the input will be call from a file ( such as To Email address, attachment path). ...
2
by: Alexander | last post by:
To all, A tall order, but any help on any segment of this would be appreciated: I have a table that needs to be populated with information contained in an email attachment. 1. Is it...
2
by: Lee | last post by:
As the subject states, I have been playing in the system trying to figure out a method of using a report as the email body text. So far, the closest I have come is the acFormatHTML. However,...
7
by: Darin | last post by:
Currently, our software is creating an email message using the Outlook DLL to send emails out that have PDF attachments. I want to stop forcing the customer to use outlook to send email. So, I...
4
by: PollyAnna | last post by:
Hi, I am fairly new to .Net and would appreciate some help. How do I open an email and its attachment programmatically. Once I have done this, is it a straightforward operation to then just...
2
by: Hanika | last post by:
Going on 3 days and I am wodnering if I am just not looking in the right place. If anyone nows how to do this please please help me. I am developing a Windows form application using VB.NET 2005....
1
by: Cylix | last post by:
My application have a file list, I set the the list will drag the file fullpath string already. When I drop it to outlook email, it pasted as a text ... How can I paste it as a attachment? ...
3
by: wpflum | last post by:
I'm using Net::POP3, Email:Simple and Email::Mime to pull emails off of a server and parse them for information to see if they are the result of 'bounced' emails from our system. I then send an email...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.