How to set the active printer for Outlook 2003

M

Mohamed Shafi P K

Hi,

I have to write an Outlook 2003 COM add-in that prints the active item to a
perticular printer. I have used a toolbar button for this purpose. Clicking
the button will direct the print to my printer. This is my idea.

I searched through the Outlook object model and I could not find a method to
set the active printer in any of the Outlook interfaces. I had wrote similar
add-ins in other Office applications (Word, Excel, PowerPoint etc.). All
these applications have interface functions put_ActivePrinter() &
get_ActivePrinter(). Only information I have is that Outlook takes the system
default printer as the active printer at startup and use the last used one
when a user manually changes/print to a printer.

Please help me if anyone has any idea to set the active printer in Outlook.

Thanks
 
S

Sue Mosher [MVP-Outlook]

You found nothing because there is nothing. You'd have to use Windows techniques to change the system default printer. Or, save the item as a ..txt, .htm, or .rtf file, open it in Word and use Word's methods.
 
M

Mohamed Shafi P K

Thanks for your information Sue.

Actually, I tried both methods you suggested:
1. I tried using Word method - I saved a mail item as html, created a word
instance inside my add-in, added a new document in word, inserted the html
file in to the document, set the active printer to my required printer, fired
the print. In this case, it works fine if my mail item has only text. But, if
it has some embedded images, it will miss in the printout. I opened the saved
html file, images are missing there also. It seems to me that Outlook uses
some internal mapping to the images used in the mail item.

I could not save the mail item as .Rtf or .doc . SaveAs function fails in
this case. (Word is my default e-mail editor - MSDN help says that "the olDoc
constant works only if Microsoft Word is set up as the default email
editor".). If it was possible, I can easily open the Rtf/Doc item using Word
:)


2. I used another process to create an Outlook instance for printing. I
changed the system default printer to my desired printer before creating
Outlook instance. I created a new mail item, put the HTML body with the
content from saved html file. This also works fine if it has text only.
Images are missing in this case also.

I could save the images used in the Outlook mail item. But I could not map
the images to the links used in the HTML to resolve the image missing problem.
I could save the mail item as .msg file, but i dont know how to open it
using Outlook interfaces. I could not found any interface methods :-(

Could you please help me regarding this? I also heared about redemption can
be used to import .msg files to Outlook. Is that possible?

Thanks in Advance
 
S

Sue Mosher [MVP-Outlook]

1) If embedded images are involved, that requires extra work -- saving the image attachments and updating <img src=> to point to the saved image files.

You can save as .rtf only if the message format is RTF.

2) That's the same HTML image problem as #1. There should be no need to create a new Outlook instance, as only one Outlook session can be running at a time.

The code sample at http://www.outlookcode.com/codedetail.aspx?id=212 shows how to open a .vcf file programmatically with the Windows Shell. The same technique should work for .msg files. Instead of colInsp.Item(1).CurrentItem.Save you could use colInsp.Item(1).CurrentItem.PrintOut.

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54
 
M

Mohamed Shafi P K

1) I could save the image attachments to a local folder from a mail item. But
I could not map the image src path in the HTML file to the saved image path
correctly in all the cases.

I used the display name property of the attachment to find a match with the
image reference in the HTML. I looked for the display name inside the image
src path. If there is the display name embedded inside the image src path, I
replaced the src path to that of the local disk path (For example, if I have
an attachment with display name=“image001.jpgâ€, I will replace an image
src=â€cid:[email protected]†with
src="C:\DOCUME~1\mohamed\LOCALS~1\Temp\1F137BC2\image001.jpg"). Most of the
cases, it works fine. But some cases image src path does not contain the
display name of the attachment (It has some number/code like
src="cid:006801c7f42e$d246b270$89c710c1@IVLGROUP).

I tried to use the index property of the attachment to map to the image src
path. Here, i tried to map the image src paths with the index order of the
attachments. But, in cases where images repeated in the mail item; it fails.

How we can map the image src path with the attachment?

2) I used another Outlook instance just to set the active printer as my
desired printer. I used another process (not from the add-in) to create an
Outlook instance.
 
S

Sue Mosher [MVP-Outlook]

You may need to use a low-level API such as CDO 1.21 or Redemption to examine hidden properties of the attachments to determine a match for the image source. The attachment's &H3712001E field should contain the CID. [TIP: A tool like Outlook Spy (http://www.dimastr.com/outspy/) or MFCMAPI.exe is a good tool for locating what fields contain the information you need. ]

The index order is not going to be helpful in this instance.
--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top