Solved

Converting email messages with attachments to pdf

Posted on 2009-05-08
19
237 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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 

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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Schedule Outlook Calendar 5 40
exchange 2007, outlook 3 41
Export Outlook 'ghost contacts' 11 38
scheduled email to be sent question. 3 27
Follow this checklist to learn more about the 15 things you should never include in an email signature from personal quotes, animated gifs and out-of-date marketing content.
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…
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…

730 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