Solved

Automatic Save function for Attachment installed in Outlook

Posted on 2003-11-26
4
374 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
Comment Utility
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
Comment Utility
> 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…

771 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

13 Experts available now in Live!

Get 1:1 Help Now