Solved

Converting email messages with attachments to pdf

Posted on 2009-05-08
19
236 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
  • 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 Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 

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 500 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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
This article lists the top 5 free OST to PST Converter Tools. These tools save a lot of time for users when they want to convert OST to PST after their exchange server is no longer available or some other critical issue with exchange server or impor…
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…
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …

831 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