Solved

Converting email messages with attachments to pdf

Posted on 2009-05-08
19
233 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
 

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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Learn more about how the humble email signature can be used as more than just an electronic business card. When used correctly, a signature can easily be tailored for different purposes by different departments within an organization.
Are you unable to connect or configure Hotmail email account in Microsoft Outlook 2010, 2007? Or Outlook.com emails are not downloading to Outlook? Lets’ see the problem and resolve Outlook Connector error syncing folder hierarchy (0x8004102A).
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…
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 …

706 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now