Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Automatic Save function for Attachment installed in Outlook

Posted on 2003-11-26
4
Medium Priority
?
402 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 500 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 500 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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…
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 process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…
Suggested Courses

885 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