Solved

Automatic Save function for Attachment installed in Outlook

Posted on 2003-11-26
4
388 Views
Last Modified: 2013-12-26
Can you help programming in VB Script to auto-save the attachment (one in each email) in defined folder for Email received daily with specific Email Subject and Sender. Noted that the Outlooked is installed with Verisign Digital Certificate decription function and the attachment need the installed key to decript.

Thanks!

Brenda.
0
Comment
Question by:brendaym
4 Comments
 
LVL 1

Accepted Solution

by:
vbs03 earned 125 total points
ID: 9830894
Hi,
Please try the following code. It is not bugfree but u can still put validation conditions as required:

Private Sub Application_NewMail()                               'This event executes as soon as new mail arrives
Set myOlApp = CreateObject("Outlook.Application")
Set myNameSpace = myOlApp.GetNamespace("MAPI")
Set myTasks = _
    myNameSpace.GetDefaultFolder(olFolderInbox)         'Get handle of Inbox folder
Set myFolder = myTasks.Folders(7)                    'Specify ur folder under Inbox folder. The one in which ur mails will arrive
Set mymailitem = myFolder.Items(1)                            'Get handle of message for which u want to perform processing
Set myAttachment = mymailitem.Attachments               'Get handle of attachment
myAttachment.Item(1).SaveAsFile "C:\" + myAttachment.Item(1).DisplayName 'Save first attachement in the C: drive root folder

End Sub

I have explained the sequence of events with required comments. This short code is just to give u an idea on how to proceed. It has been written using VBA in Outlook. U can generalise this further as required and also include Error handling conditions. In case u have any further queries please reply to this post.
0
 
LVL 7

Assisted Solution

by:wsteegmans
wsteegmans earned 125 total points
ID: 9833076
> Noted that the Outlooked is installed with Verisign Digital Certificate decription function
> and the attachment need the installed key to decript

What we need is Outlook Redemption. Outlook Redemption (http://www.dimastr.com/redemption) is a programming library developed by an Outlook Most Valuable Professional (MVP—Microsoft's award for volunteers who help other people get more from Microsoft products). Because Redemption is similar to the Outlook object model, converting most Outlook code to Redemption code is relatively easy.

More info about Outlook Redemption can be found here:
- http://www.dimastr.com/redemption/home.htm                        <-- Download here Redemption DLL-File!
- http://techrepublic.com.com/5100-6270-1032953.html
- http://www.winnetmag.com/Articles/ArticleID/24411/pg/1/1.html

Your program could be like this short example (VB-code, so little modifications to become VBS):

Sub RedemptionMailAtt()

  Dim oOutlook As Outlook.Application
  Dim oFldr As Outlook.MAPIFolder
  Dim oMsg As Redemption.SafeMailItem
  Dim oAtt As Redemption.Attachment
  Dim oMessage As Outlook.MailItem
  Dim oNs As Outlook.NameSpace
  Dim mSubject As String, mFrom As String, mBody As String
 
' Initialize Outlook App ...
  Set oOutlook = New Outlook.Application
  Set oNs = oOutlook.GetNamespace("MAPI")
  Set oFldr = oNs.PickFolder
' If you just want you inbox, use this line ...
  Set oFldr = oNs.GetDefaultFolder(olFolderInbox)
 
' Create Safe MailMessage Object
  Set oMsg = New Redemption.SafeMailItem

' Authenticate object
  oMsg.AuthKey = "*******"


  For Each oMessage In oFldr.Items
      oMsg.Item = oMessage
' - - If Mail is Unread, and is a real Mail (no appointment, ...) and the sender is X and the Subject is Y ...
      If oMessage.UnRead = True And _
         oMessage.MessageClass = "IPM.Note" And _
         oMsg.SenderName = "SenderName" And _
         oMessage.Subject = "MySubject" Then
' - - - Save all Attachments in mailmessage
        For Each oAtt In oMsg.Attachments
          oAtt.SaveAsFile "Path" & oAtt.FileName
        Next oAtt
      End If
  Next oMessage
 
' Destructor
  Set oOutlook = Nothing
  Set oNs = Nothing
  Set oFldr = Nothing
  Set oMsg = Nothing

End Sub
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question