Rocket Software Homepage
Forum Home Forum Home > AccuTerm Knowledge Base (read only) > Scripting & Automation
  New Posts New Posts RSS Feed - How to get a PDF Outlook attachment to Linux
  FAQ FAQ  Forum Search   Register Register  Login Login

The AccuTerm forum has moved. Go to community.rocketsoftware.com to register for the new Rocket forum.

Forum LockedHow to get a PDF Outlook attachment to Linux

 Post Reply Post Reply
Author
Message
dlaansma View Drop Down
Newbie
Newbie


Joined: March 05 2010
Location: United States
Status: Offline
Points: 9
Post Options Post Options   Thanks (0) Thanks(0)   Quote dlaansma Quote  Post ReplyReply Direct Link To This Post Topic: How to get a PDF Outlook attachment to Linux
    Posted: September 02 2015 at 11:52am
Our company receives a large number of PDF documents from a customer and I'm writing the necessary code to automate the conversion and importing of that document into our Unidata database, running on Linux.

Right now it's a two-step process for the user:

1. Open the email in Outlook, right-click the PDF attachment, save-as in a predefined location and file name.

2. In Unidata, run my program that copies that raw PDF file from the user's PC to Linux, run that file through the Linux program pdftotext, scrape that text file for the necessary data and produce the respective order information into our backend system.

I'd REALLY like to make this a one-step process. In other words, I'd like to run (some version of) my Outlook script from Accuterm so the user only has to have the email 'selected' in outlook, then run my program that will do both of those steps in one command.

Following is the Outlook script that I'd like to create and run from Accuterm. I'm not fluent in vBasic but I'm trying to get that way. Any help would be appreciated.

Option Explicit

Public Sub SaveAttachments()
Dim objOL As Outlook.Application
Dim objMsg As Outlook.MailItem 'Object
Dim objAttachments As Outlook.Attachments
Dim objSelection As Outlook.Selection
Dim i As Long
Dim lngCount As Long
Dim strFile As String
Dim strFolderpath As String
Dim strDeletedFiles As String

strFolderpath = CreateObject("WScript.Shell").SpecialFolders(16)
On Error Resume Next

Set objOL = CreateObject("Outlook.Application")

Set objSelection = objOL.ActiveExplorer.Selection

strFolderpath = "c:\hubbard\"

For Each objMsg In objSelection

    Set objAttachments = objMsg.Attachments
    lngCount = objAttachments.Count
    strDeletedFiles = ""

    If lngCount > 0 Then
        For i = lngCount To 1 Step -1

            strFile = objAttachments.Item(i).FileName
            strFile = "gmsaporder.pdf"

            strFile = strFolderpath & strFile

            objAttachments.Item(i).SaveAsFile strFile

            If objMsg.BodyFormat <> olFormatHTML Then
                strDeletedFiles = strDeletedFiles & vbCrLf & "<file://" & strFile & ">"
            Else
                strDeletedFiles = strDeletedFiles & "<br>" & "<a href='file://" & _
                strFile & "'>" & strFile & "</a>"
            End If

            MsgBox objAttachments.Item(i) & " has been saved to your PC. Proceed to Prelude and import it now."
        Next i

        If objMsg.BodyFormat <> olFormatHTML Then
            objMsg.Body = vbCrLf & "The file(s) were saved to " & strDeletedFiles & vbCrLf & objMsg.Body
        Else
            objMsg.HTMLBody = "<p>" & "The file(s) were saved to " & strDeletedFiles & "</p>" & objMsg.HTMLBody
        End If
        objMsg.Save
    End If
Next

ExitSub:

Set objAttachments = Nothing
Set objMsg = Nothing
Set objSelection = Nothing
Set objOL = Nothing
End Sub


p.s. the above script was shamelessly copied from a website somewhere on the web. I lay no claim to an intimate knowledge of vBasic or this script in particular. I was able to understand it enough to make the changes I needed to get the file to be located and named exactly as I needed it to. However I fail to have the skills it takes to translate this into a script that can be execute utilizing the Accuterm toolset for executing said scripts.
Dave Laansma
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.03
Copyright ©2001-2019 Web Wiz Ltd.