?
Solved

Converting email messages with attachments to pdf

Posted on 2009-05-08
19
Medium Priority
?
239 Views
Last Modified: 2012-05-06
Hi,
How to convert  email messages with attachments to pdf in vb6.0.


Cheers
0
Comment
Question by:RIAS
[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
  • 10
  • 9
19 Comments
 
LVL 76

Expert Comment

by:David Lee
ID: 24334321
Hi, RIAS.

Do you have Acrobat or another tool for creating PDFs?
0
 

Author Comment

by:RIAS
ID: 24334443
Hi,
Yes I have an activex 'pegasus'
0
 
LVL 76

Expert Comment

by:David Lee
ID: 24334950
I'm not familiar with Pegasus so I can't tell you how to use it.  I can describe how to get an Outlook message and save it and its attachments to disk.  That is the first step in doing this.  You'd have to work out how to create the PDF with Pegasus.  is that what you're looking for?
0
NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

 

Author Comment

by:RIAS
ID: 24335544
Hi,
I would appreciate if you could guide me on  a Outlook message and save it and its attachments to disk.

Cheers
0
 
LVL 76

Accepted Solution

by:
David Lee earned 2000 total points
ID: 24341088
Here's an example of how to save the message and all its attachments to disk.  This would save the currently selected message and its attachments.
'Change the folder path on the following line as needed'
Const FolderName = "C:\eeTesting\"
Dim olkApp, olkSes, olkMsg, olkAttachment
Set olkApp = CreateObject("Outlook.Application")
Set olkSes = olkApp.GetNameSpace("MAPI")
'Change the profile name on the next line'
olkSes.Logon "Outlook"
Set olkMsg = olkApp.ActiveExplorer.Selection(1)
olkMsg.SaveAs FolderName & olkMsg.Subject & ".txt", olTXT
For Each olkAttachment In olkMsg.Attachments
    olkAttachment.SaveAsFile FolderName & olkAttachment.FILENAME
Next
Set olkAttachment = Nothing
Set olkMsg = Nothing
olkSes.Logoff
Set olkSes = Nothing
Set olkApp = Nothing

Open in new window

0
 

Author Comment

by:RIAS
ID: 24344330
Hi,
Cheers mate will try it when back to work on Monday...
0
 
LVL 76

Expert Comment

by:David Lee
ID: 24344846
Cool.
0
 

Author Comment

by:RIAS
ID: 24352524
Hi BlueDevilFan,

Tried your solution it works great but a small query is that in my application I have already stored the msg file in .msg format on my C drive so can I specify path here
Set olkMsg = olkApp.ActiveExplorer.Selection(1)
If yes then how do I define olkMsg

Cheers



0
 
LVL 76

Expert Comment

by:David Lee
ID: 24352583
That poses a problem.  Outlook's object model doesn't provide a way to open an item stored on disk in .msg file format.  Doing that requires using a 3rd-party tool like Outlook Redemption (http://www.dimastr.com/redemption).
0
 

Author Comment

by:RIAS
ID: 24352614
Hi,
Is there any way out other than using the third party software?
0
 

Author Comment

by:RIAS
ID: 24352700
Hi,
I am using ' pdf995' any suggestions?
0
 
LVL 76

Expert Comment

by:David Lee
ID: 24352716
There are two possibilities.

1.  Use a shell command like the example in the snippet.  I believe the command is asynchronous so it's possible that your next command will occur before the message has opened.

2.  Use Outlook's CreateItemFromTemplate method.  This will create a new message using the saved message as a template.  This approach loses some of the information from the original message.  For example the message sender, time sent, time received, etc. will not be available to the resulting new message.  
Sub OpenMsgFile(strFilename As String)
    ShellExecute 0&, "Open", strFilename, "", "C:\", 1
End Sub

Open in new window

0
 
LVL 76

Expert Comment

by:David Lee
ID: 24352728
Oops, I forgot to include the API function declaration for the ShellExecute command.  This is the way the snippet should have read.
Private Declare Function ShellExecute Lib "shell32.dll" _
  Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, _
  ByVal lpFile As String, ByVal lpParameters As String, _
  ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
 
Sub OpenMsgFile(strFilename As String)
    ShellExecute 0&, "Open", strFilename, "", "C:\", 1
End Sub

Open in new window

0
 
LVL 76

Expert Comment

by:David Lee
ID: 24352739
Sorry, I've no experience with PDF converting programs.
0
 

Author Comment

by:RIAS
ID: 24352790
Cheers mate for helping will try your solution and get back
0
 

Author Comment

by:RIAS
ID: 24353089
Hi,
It does open the file but not sure how to assign it to
Set olkMsg
Tried this
Set olkMsg = OpenMsgFile("ABC.msg")
But it errored
Cheers
0
 

Author Comment

by:RIAS
ID: 24354010
Cheers mate for the help so far but not getting a result so need to post the question again
0
 
LVL 76

Expert Comment

by:David Lee
ID: 24354700
You'd assign it to olkMsg like this

    OpenMsgFile "ABC.msg"
    Set olkMsg = Outlook.Application.ActiveInspector.CurrentItem

The problem, as I noted above, is that the second line could execute before the message appears in the inspector window.  
0
 

Author Comment

by:RIAS
ID: 24355476
Cheers mate..deleted the question posted  again...just working on your solution....thanks for the effort will get backas soon as it works
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
If you troubleshoot Outlook for clients, you may want to know a bit more about the OST file before doing your next job. IMAP can cause a lot of drama if removed in the accounts without backing up.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
CodeTwo Sync for iCloud (http://www.codetwo.com/sync-for-icloud?sts=6554) automatically synchronizes your Outlook 2016, 2013, 2010 or 2007 folders with iCloud folders available via iCloud Control Panel. This lets you automatically sync them with…
Suggested Courses

762 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