Solved

Automatic Save function for Attachment installed in Outlook

Posted on 2003-11-26
4
390 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

734 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