ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

Main Area and Open Discussion > General Software Discussion

.Intercepting/rewriting Outlook HTML emails automagically

(1/3) > >>

CodeTRUCKER:
Below is some code I scavenged from the Internet for a macro that will take attached images in Outlook 2002 and display them in a window. 

Does anyone know how to intercept an email w/ pix attchments in a locale Outlook client and "rewrite" the HTML so the pix display in the body automagically?

I have tried some experiments with the code below, but I don't know how to intercept the email before it is displayed in my client.

Is this possible?


Thanks! :)



--- Code: Visual Basic ---Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)  Sub view_attachments()'***************************************************************' ver. 1/30/04'  - Select one or multiple emails.'  - Copies files to 'Temporary Internet Files\view_attachments''    (previously copied files are deleted each time it's run).'  - Only image files are displayed (no others are executed).'  - Right-click images to 'Save As', 'Email', 'Print', etc.'  - Hover over image to see original size & scaled size.'  - Clicking each image will toggle between original size'    & browser width (unless original size is smaller).'  - To scale all images to browser width, resize the browser,'    right-click on background & choose 'Refresh'.'***************************************************************On Error Resume Next      Dim oOL As Outlook.Application    Dim oSelection As Outlook.Selection      Set oOL = New Outlook.Application    Set oSelection = oOL.ActiveExplorer.Selection    Set objShell = CreateObject("WScript.Shell")    Set fs = CreateObject("Scripting.FileSystemObject")      vTempInt = objShell.RegRead("HKCU\software\microsoft\" _      & "Windows\CurrentVersion\Explorer\Shell Folders\Cache")    vPath = vTempInt & "\view_attachments\"      If fs.FolderExists(vPath) Then        fs.DeleteFile (vPath & "*.*")    Else        fs.CreateFolder vPath    End If      vBkgrColor = "000000"    vFontColor = "FFFFFF"    vHTMLBody = "<HTML><title>View Email Attachments</title>" _      & "<body bgcolor=#" & vBkgrColor & " link=#" & vFontColor _      & " alink=#" & vFontColor & " vlink=#" & vFontColor _      & "><font face=Arial size=3 color=#" & vFontColor & ">"      vEmailNum = 0    For Each obj In oSelection        vEmailNum = vEmailNum + 10        vSubject = "Attachments from: <a href=""Outlook:" _          & obj.EntryID & """><b>" & obj.Subject & "</b></a><br>"        vHTMLBody = vHTMLBody & vSubject        vAttachNum = vEmailNum        For Each Attachment In obj.Attachments            vAttachNum = vAttachNum + 1            vImg = "document.img" & vAttachNum            vWidth = "document.body.clientWidth - 20"            Attachment.SaveAsFile (vPath & Attachment.FileName)            vHTMLBody = vHTMLBody _              & "<b>" & Attachment.FileName & "</b><br>" _              & "<a href=""javascript:fWidth(" & vImg & ");"">" _              & "<center><IMG name=""img" & vAttachNum & """ alt="""" hspace=0 " _              & "src=""" & vPath & Attachment.FileName & """ align=baseline " _              & "border=0 " & "onload=""vOrig=String(" & vImg & ".width)" _              & "+ ' x ' + String(" & vImg & ".height);vRatio=(" & vWidth _              & ")/" & vImg & ".width;" & vImg & ".alt='Original Size: ' + " _              & "vOrig + '\n  Scaled Size: ';if(" & vImg & ".width <=" _              & vWidth & "){" & vImg & ".alt=" & vImg & ".alt + vOrig;}" _              & "else{" & vImg & ".alt=" & vImg & ".alt + String(" & vWidth _              & ")+ ' x ' + String(Math.round(vRatio *" & vImg & ".height));}" _              & "if (" & vImg & ".width >" & vWidth & "){" & vImg & ".width = " _              & vWidth & ";}""></center></a><br><br><br>"        Next        vHTMLBody = vHTMLBody & "</a><br><br>"    Next      If Not vImg = "" Then        vHTMLBody = vHTMLBody & "<script>function fWidth (vImg){" _          & "vCRLF=vImg.alt.indexOf('\n');vOrgWidth=vImg.alt.substring" _          & "(vImg.alt.indexOf(':')+2, vImg.alt.indexOf('x')-1);" _          & "if(vImg.width == " & vWidth & "|| vOrgWidth <= " & vWidth _          & "){vImg.width=vOrgWidth;vImg.alt=vImg.alt.substring(0,vCRLF)" _          & "+ '\n  Scaled Size: '+ vImg.alt.substring(vImg.alt." _          & "indexOf(':')+2,vCRLF);}else{vImg.width=" & vWidth & ";" _          & "vImg.alt=vImg.alt.substring(0,vCRLF) + '\n  Scaled Size: '" _          & "+ String(" & vWidth & ")+ ' x ' + String(vImg.height);}}</script>"    End If      vHTMLBody = vHTMLBody & "</font></body></html>"      Set ie = CreateObject("internetexplorer.application")    With ie        .toolbar = 0        .menubar = 0        .statusbar = 0        .Left = 100        .Top = 50        .Height = 750        .Width = 1000        .navigate "about:blank"        .document.Open        .document.Write vHTMLBody        .document.Close        .Visible = True    End With      vTimer = 0    Do Until ie.readyState = 4 Or vTimer = 10000        Sleep 10        vTimer = vTimer + 10    Loop      Set ie = Nothing    Set fs = Nothing    Set objShell = Nothing    Set oSelection = Nothing    Set oOL = NothingEnd Sub

tinjaw:
codeTRUCKER,

Off the top of my head I can think of two ways to do that.

1) Put something in the middle of Outlook and the mail server. Just like a proxy. That proxy would introspect all incoming emails (which are just strings of ASCII text - binaries are MIME encoded) and rewrite the emails as desired. You could use the tool of you choice to create this proxy.

2) Since you are using Outlook, you can use VBA (or any scripting language compatible with the scripting host, like Jscript) and interact with Outlook. You basically make an add-on for Outlook.

BigJim:
2) Since you are using Outlook, you can use VBA (or any scripting language compatible with the scripting host, like Jscript) and interact with Outlook.
-tinjaw (February 03, 2008, 06:18 AM)
--- End quote ---

I sure wish somebody would do that. It's so annoying that Outlook handles attached images so poorly. M/$ says it's because of security. Humbug! From time to time I go hunting for a solution and am again amazed that there seem to be few or no solutions available.

I had an application a while back (can't recall the name just now) which worked OK. Would have gladly coughed up $10 for it but all the links to buy it were dead. Then the trial expired and it gaged.

The app didn't display the images in the message but when you clicked on any of several attached images and your viewer launched you could then page through all of them instead of having to go back to the message and open each one individually.

CodeTRUCKER:
2) Since you are using Outlook, you can use VBA (or any scripting language compatible with the scripting host, like Jscript) and interact with Outlook.
-tinjaw (February 03, 2008, 06:18 AM)
--- End quote ---

I sure wish somebody would do that. It's so annoying that Outlook handles attached images so poorly. M/$ says it's because of security. Humbug! From time to time I go hunting for a solution and am again amazed that there seem to be few or no solutions available.
-BigJim (February 05, 2008, 12:06 AM)
--- End quote ---

Hi Jim,

Me too!  I am looking into this as I am not satisfied with the way OE handles it.  I know "what" to do to make it work, but I have to learn "how" to program it (read: learn syntax).   

I had an application a while back (can't recall the name just now) which worked OK. Would have gladly coughed up $10 for it but all the links to buy it were dead. Then the trial expired and it gaged.

The app didn't display the images in the message but when you clicked on any of several attached images and your viewer launched you could then page through all of them instead of having to go back to the message and open each one individually.

--- End quote ---

The macro I posted in the first post above will provide the function you have described.  :) 
After the macro has been saved, I reccomend creating a button to put on the toolbar in OE.  When you have picture attachments in a mail, just click run the macro and voila!  A simple browser will open with all the pictures and if you select multiple mails in the message list, it will display all the pictures in all the mails in one window.  Scroll down to see all of them.

Hope this helps.

Fair winds!

BigJim:
Sounds interesting. And thanks!

This is embarrassingly lame but when I try to copy/paste your script into the VB editor it keeps throwing in CR/LF's and it won't run. Needless to say, an avid participant I am. But a coder I'm not!

Help

Navigation

[0] Message Index

[#] Next page

Go to full version