• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 246
  • Last Modified:

Converting email messages with attachments to pdf

Hi,
How to convert  email messages with attachments to pdf in vb6.0.


Cheers
0
RIAS
Asked:
RIAS
  • 10
  • 9
1 Solution
 
David LeeCommented:
Hi, RIAS.

Do you have Acrobat or another tool for creating PDFs?
0
 
RIASAuthor Commented:
Hi,
Yes I have an activex 'pegasus'
0
 
David LeeCommented:
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
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
RIASAuthor Commented:
Hi,
I would appreciate if you could guide me on  a Outlook message and save it and its attachments to disk.

Cheers
0
 
David LeeCommented:
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
 
RIASAuthor Commented:
Hi,
Cheers mate will try it when back to work on Monday...
0
 
David LeeCommented:
Cool.
0
 
RIASAuthor Commented:
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
 
David LeeCommented:
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
 
RIASAuthor Commented:
Hi,
Is there any way out other than using the third party software?
0
 
RIASAuthor Commented:
Hi,
I am using ' pdf995' any suggestions?
0
 
David LeeCommented:
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
 
David LeeCommented:
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
 
David LeeCommented:
Sorry, I've no experience with PDF converting programs.
0
 
RIASAuthor Commented:
Cheers mate for helping will try your solution and get back
0
 
RIASAuthor Commented:
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
 
RIASAuthor Commented:
Cheers mate for the help so far but not getting a result so need to post the question again
0
 
David LeeCommented:
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
 
RIASAuthor Commented:
Cheers mate..deleted the question posted  again...just working on your solution....thanks for the effort will get backas soon as it works
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

  • 10
  • 9
Tackle projects and never again get stuck behind a technical roadblock.
Join Now