Solved

Automatic Save function for Attachment installed in Outlook

Posted on 2003-11-26
4
381 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

910 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now