?
Solved

Can I write a script to just print attachments in Outlook 2003?

Posted on 2009-05-08
5
Medium Priority
?
266 Views
Last Modified: 2012-05-06
I have multiple emails with attachments that I would like to have print automatically unattended when the email arrives.  I know I can print an email using a rule, but it does not print the attachment.  Any thoughts?

I have tried using the code put up by others on this site, but it seems to do nothing.  Maybe I'm not doing something right.
0
Comment
Question by:TJWheelz68
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 

Expert Comment

by:baburajpanicker
ID: 24338291
you can write a small java (java mail) application ( 1 or 2 java files) which will download the attachments for all unread mails and send to the printer.
0
 
LVL 59

Accepted Solution

by:
Chris Bottomley earned 1000 total points
ID: 24338316
Hello TJWheelz68,

Two stages really:

1. A script that will print the attachments ... i.e. as below which when placed in an ordinary module will in association with a rule print the files automatically on receipt.

2. Create a rule to run the script for every incoming email.

Let me know ...

Chris

Regards,
Chris
Function PrintAttachments(mai As mailitem)
Dim objFSO As Object
Dim objTempFolder As Object
Dim olkAttachment As Outlook.Attachment
Dim olkItem As Object
 
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objTempFolder = objFSO.GetSpecialFolder(2)
    For Each olkItem In Application.ActiveExplorer.Selection
        For Each olkAttachment In olkItem.Attachments
                olkAttachment.SaveAsFile objTempFolder & "\" & olkAttachment.fileName
                ShellExecute 0&, "print", objTempFolder & "\" & olkAttachment.fileName, 0&, 0&, 0&
        Next
    Next
    
Set olkItem = Nothing
Set olkAttachment = Nothing
Set objTempFolder = Nothing
Set objFSO = Nothing
End Function

Open in new window

0
 

Assisted Solution

by:baburajpanicker
baburajpanicker earned 1000 total points
ID: 24345075
import java.io.*;
import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.*;

public class GetParts {
  public static void main (String args[])
      throws Exception {
    String host = args[0];
    String username = args[1];
    String password = args[2];

    // Get session
    Session session = Session.getInstance(
      new Properties(), null);

    // Get the store
    Store store = session.getStore("pop3");
    store.connect(host, username, password);

    // Get folder
    Folder folder = store.getFolder("INBOX");
    folder.open(Folder.READ_ONLY);

    BufferedReader reader = new BufferedReader (
      new InputStreamReader(System.in));

    // Get directory
    Message message[] = folder.getMessages();
    for (int i=0, n=message.length; i<n; i++) {
       System.out.println(i + ": "
         + message[i].getFrom()[0]
         + "\t" + message[i].getSubject());

      System.out.println(
        "Do you want to get the content?
           [YES to read/QUIT to end]");
      String line = reader.readLine();
      if ("YES".equals(line)) {
        Object content = message[i].getContent();
        if (content instanceof Multipart) {
          handleMultipart((Multipart)content);
        } else {
          handlePart(message[i]);
        }
      } else if ("QUIT".equals(line)) {
        break;
      }
    }

    // Close connection
    folder.close(false);
    store.close();
  }
  public static void handleMultipart(Multipart multipart)
      throws MessagingException, IOException {
    for (int i=0, n=multipart.getCount(); i<n; i++) {
      handlePart(multipart.getBodyPart(i));
    }
  }
  public static void handlePart(Part part)
      throws MessagingException, IOException {
    String disposition = part.getDisposition();
    String contentType = part.getContentType();
    if (disposition == null) { // When just body
      System.out.println("Null: "  + contentType);
      // Check if plain
      if ((contentType.length() >= 10) && 
          (contentType.toLowerCase().substring(
           0, 10).equals("text/plain"))) {
        part.writeTo(System.out);
      } else { // Don't think this will happen
        System.out.println("Other body: " + contentType);
        part.writeTo(System.out);
      }
    } else if (disposition.equalsIgnoreCase(Part.ATTACHMENT)) {
      System.out.println("Attachment: " + part.getFileName() +
        " : " + contentType);
      saveFile(part.getFileName(), part.getInputStream());
    } else if (disposition.equalsIgnoreCase(Part.INLINE)) {
      System.out.println("Inline: " +
        part.getFileName() +
        " : " + contentType);
      saveFile(part.getFileName(), part.getInputStream());
    } else {  // Should never happen
      System.out.println("Other: " + disposition);
    }
  }
  public static void saveFile(String filename,
      InputStream input) throws IOException {
    if (filename == null) {
      filename = File.createTempFile("xx", ".out").getName();
    }
    // Do no overwrite existing file
    File file = new File(filename);
    for (int i=0; file.exists(); i++) {
      file = new File(filename+i);
    }
    FileOutputStream fos = new FileOutputStream(file);
    BufferedOutputStream bos = new BufferedOutputStream(fos);

    BufferedInputStream bis = new BufferedInputStream(input);
    int aByte;
    while ((aByte = bis.read()) != -1) {
      bos.write(aByte);
    }
    bos.flush();
    bos.close();
    bis.close();
  }
}
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 24534860
Hello TJWheelz68,

Any update?

Chris
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

If you troubleshoot Outlook for clients, you may want to know a bit more about the OST file before doing your next job. IMAP can cause a lot of drama if removed in the accounts without backing up.
In this article I discuss my selections of the Top Four free Outlook OST File Viewers available. Open, view and read even damaged OST files by using these tools. They all provide a clear preview of all data such as emails, notes, tasks, calendars, e…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…

718 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