Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hi, I need to print mails from my 1

Status
Not open for further replies.

marlo

Technical User
Jan 23, 2004
9
IN
Hi,
I need to print mails from my inbox which are sent to a particular distribution list(I am part of the list) along with attachments.
Can anyone help me with this ?

Thanks in advance.
 
Which e-mail program are you using? If Outlook, is it 2000 or higher? There was no support for Distribution lists in the 97/98 object models.

Paul Bent
Northwind IT Systems
 
I am using Outlook 2000.
I have found a s/w on the net that allows me to do this (Caprint from Ornic USA).

Paul thanks for your help.

 
Thanks for letting us know. It wouldn't be too hard to do this in VB but might be a bit long winded; you'd have to save each attachment to a temp folder, print it in it's registered app with ShellExecute then delete it.

Paul Bent
Northwind IT Systems
 
Can you tell me how to go about printing all the items in a folder once I have stored my mails and attachments in it.
I need to write a VB code for this because CaPrint does not allow me to fire prints at a particular time which is a prerequisite of my project.

The contents of the folder are dynamic and the attachments could have all types of file extensions.


 
Here's a rough idea; I'm just typing this in so excuse any errors. Say the e-mails are stored in a MAPI folder, Inbox\Print and the attachments are temporarilly saved to and printed from a file system folder, c:\temp.
Code:
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

Public Const SW_HIDE = 0   'Hide the opened window
'________________________________________________

Sub PrintItems

 Dim objApp As Outlook.Application
 Dim objNS As Outlook.Namespace
 Dim objFolder As MAPIFolder
 Dim objMsg As MailItem
 Dim objAttach As Attachment
 Dim strFile As String
 Dim intC1 As Integer

 Set objApp = CreateObject("Outlook.Application")
 Set objNS = objApp.GetNamespace("MAPI")
 'Get the folder containing the items to print
 Set objFolder = objNS.GetDefaultFolder(olFolderInbox).Folders("Print")
 'Move through the items collection
 Set objMsg = objFolder.Items.GetFirst
 Do While Not objMsg Is Nothing
  'Print the e-mail
  objMsg.PrintOut
  'Move through the attachments collection
  If objMsg.Attachments.Count > 0 Then
   For intC1 = 0 To objMsg.Attachments.Count - 1
    'Get the filename
    Set objAttach = objMsg.Attachments.Item(intC1)
    strFile = "c:\temp\" & objAttach.FileName
    'Save the attachment
    objAttach.SaveAsFile strFile
    'Print it
    ShellExecute Me.hWind, "print", strFile, _
    vbNullString, vbNullString, SW_HIDE
   Next
  End If
  Set objMsg = objFolder.Items.GetNext
 Loop

 'Delete all the files in c:\temp here if required

 Set objAttach = Nothing
 Set objMsg = Nothing
 Set objFolder = Nothing
 Set objNS = Nothing
 Set objApp = Nothing

End Sub

Paul Bent
Northwind IT Systems
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top