Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1659
  • Last Modified:

Download attachment from Outlook.

I would like to develope a service in visual basic 6.0, which downloads the attacthment from the outlook and save it in the particular folder. As soon as user receive a mail with an attachment, that attachment will be downloaded in the folder. The mails which are coming is from various clients about 50 clients. Pls give me the solution. If u can send me the some kind of code also then it will be beneficial to me.
0
jeet_nbi
Asked:
jeet_nbi
1 Solution
 
Ryan ChongCommented:
Answer this similar question before, let me do a quick search first :)
0
 
Ryan ChongCommented:
Still find original solution, but you can refer to this also:

Save Attachments From the Outlook Inbox to a File:
http://www.freevbcode.com/ShowCode.Asp?ID=1154
0
 
Ryan ChongCommented:
Here is it:

Read the Inbox Folder to see if it's a New Email, if it got attachments, save it into specified directory:

Private Sub Command3_Click()
   Dim iOutlook As Outlook.Application
   Dim myitem As Outlook.MailItem
   Dim myFolder As Outlook.MAPIFolder
   Dim myAttach As Outlook.Attachment
   Set iOutlook = New Outlook.Application
   
   Set myFolder = iOutlook.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox)

   List1.Clear
   For i = 1 To myFolder.Items.Count
       Set myitem = myFolder.Items(i)
       If myitem.UnRead = True And myitem.Attachments.Count > 0 Then 'If the Item is UnRead and With
Attachment(s)
           List1.AddItem myitem.SenderName & " " & myitem.Subject
           For j = 1 To myitem.Attachments.Count
               Set myAttach = myitem.Attachments(j)
               myAttach.SaveAsFile "D:\" & myAttach.FileName
           Next j
           DoEvents
       End If
   Next i
   Set myitem = Nothing
   Set myFolder = Nothing
   Set iOutlook = Nothing
End Sub

* Remove the myitem.UnRead = True  from the code above if you want to check all the mails in Inbox folder.

regards,
ryancys
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
jeet_nbiAuthor Commented:
Dear Ryancys,
Thanks for your prompt reply. But sorry to say that code is giving me the problem. While running the following code its giving me the type mismatch error.
Set myitem = myFolder.Items(i)
Please solve my problem. Its Urgent.

Thanks
Jeetendra

0
 
Ryan ChongCommented:
Forget to tell, you need to add the M$ Outlook 9.0 Object Library from your References. Add this reference and run the code above again, it should working well.

regards
0
 
Ryan ChongCommented:
Hi jeet_nbi,

Any progress? The code above tested to be working.
0
 
jeet_nbiAuthor Commented:
Hi Ryancys,
I don't have the Outlook 8.0 library. As soon as i get it i will try and get back to u. Thanks again.
Jeet.
0
 
jeet_nbiAuthor Commented:
Sorry I don't have the outlook library 9.0. I have 8.0.

jeet
0
 
Ryan ChongCommented:
It's ok, so you got office/outlook 97 (let me guess)? Just add this reference (8.0) in your project and try to run the code above.
0
 
jeet_nbiAuthor Commented:
Hi Ryancys,
I have got the msoutl9.olb file and copy it in the system32 directory, and given the reference in the project.I have tried to run the project but its gives me the error :Variables uses an automation type does not supported in VB while creating the outlook application object. Earlier I had tried this with lib 8.0, every thing was ok, outlook application object was created, but gives me a error while creating mailitem object. Now give me the solution.
Thanks for the help.
Jeet
0
 
Ryan ChongCommented:
I think you can't just copy the msoutl9.olb to system, this is a wrong step. For your information, the msoutl9.olb is for Office 2k (outlook 2k), so it involve the installation of office 2k. Make sure you install office 2k in proper way.

The references in VB project is simple:

M$ Outlook Object 8.0 Library is for Outlook 97, 9.0 is for Outlook 2000, 10.0 is for Outlook XP.

It's depends on the client's pc and their requirement to determine which library to use, but basically for safety use the lower version of library, if the code not run smoothly, upgrade the library to higher level.

regards,
ryancys
0
 
DanRollinsCommented:
Hi jeet_nbi,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Accept ryancys's comment(s) as an answer.

jeet_nbi, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept this comment as an answer.
==========
DanRollins -- EE database cleanup volunteer
0
 
SpideyModCommented:
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now