?
Solved

Converting email messages with attachments to pdf

Posted on 2009-05-08
19
Medium Priority
?
242 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

This article lists the top 5 trialware 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 other critical issues with Exchange server or impo…
Mailbox Corruption is a nightmare every Exchange DBA wishes he never has. Recovering from it can be super-hectic if not entirely futile. And though techniques like the New-MailboxRepairRequest cmdlet have been designed to help with fixing minor corr…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses
Course of the Month17 days, 10 hours left to enroll

830 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