📜 ⬆️ ⬇️

Sending large files in Microsoft Outlook 2010 using VBA and PHP

I want to share a way to solve the problem of sending large files to Microsoft Outlook 2010 (I think from 2013, too,).
So, the initial conditions are:
- MS Exchange Server 2010 - inhouse - no admin access - the author is just a user
- Restrictions on the total amount of letters 10Mb
- There are a couple of Linux web servers in their DMZ and admin access to corporate intranets
It is necessary:
- Organize a convenient mechanism for transferring large files (very large)
- Do not use third-party providers to store information

The first thought was to use services like dropbox, or rather their self-hosted analogues of ownCloud type. However, to deploy this all just for attachments seemed inadequate.

In addition, how to attach inside outluka is still unclear. There is more suitable option with plug-ins, like the one that offers such as YouSendIt and other similar services. It looks like this: in Outlook, a button appears when you click on a service window that pops up to where our large attachment file is uploaded; when the download is complete, a link to it is generated and inserted into the message body. Since we cannot use these types of services and, accordingly, their plugins, we will make them analogous.

Stage 1. Online file sharing service
It's pretty simple, since there are projects of this kind with an open source license. I chose PLUpload , and installed it on one of the Linux servers in our DMZ. The scripts were slightly modified namely:
- a password is requested or a session is checked (with the support of SSO authentication) through a corporate intranet, approximately as described here
- if the file is successfully downloaded, the generated URL is added to the invisible element txtList to download it (why it will be necessary to understand it from the next step)
- I also added cron to remove old links - in order to save disk space
')
Restrictions on size depend on the settings of PHP and the web server, I have set a limit of 2 GB per file (you can attach up to 10 files at the same time).

Stage 2. Client part
Ideally, this should be an Outlook Plug-in, but as far as I understand it, plug-ins are not so easy to do and I won't waste time on it ...
Instead, I did a normal VBA project and screwed it to the toolbar in Outlook.

The project consists of the form on which are placed:
- standard button with the title Attach
- standard WebBrowser control (actually frame IE)

It looks like this


Next comes the code for this all in Visual Basic, I apologize in advance if someone will find it not comme il faut, I'm not quite a programmer (not a VB programmer - that's for sure)

VBA code of the project
Private Sub CommandButton1_Click() If WebBrowser1.Document.all("txtList").Value = "" Then MsgBox "No files have been uploaded" + vbNewLine + "Please make sure you click on 'Start upload' and upload is 100% completed" Else On Error GoTo MessageACT Set objMail = Outlook.Application.ActiveInspector.CurrentItem If objMail.BodyFormat = olFormatHTML Then ' objMail.HTMLBody = objMail.HTMLBody + "<hr>Attached" + Attachment1 incMess = "" Attachment1 = WebBrowser1.Document.all("txtList").Value Expires1 = WebBrowser1.Document.all("txtDate").Value preText = "<font size=1>------------------------------------</font><br><b>Large Attachments</b><br>" + vbNewLine posttext = vbNewLine + "<br><font size=1>Attachments added via filesharingserverindmz.cool <br> powered by owners </font><br>-------------------" filesAtt = Split(Attachment1, "|") For Each itm In filesAtt If itm <> "" Then ATTmsg = ATTmsg + "<a href='https://filesharingserverindmz.cool/get/" + itm + "'>https://filesharingserverindmz.cool/get/" + itm + "</a><br>" + vbNewLine End If Next itm incMess = preText + ATTmsg + vbNewLine + "<br>the attachments will be valid for <b>" + Expires1 + "</b> days from now" + vbNewLine + posttext objMail.HTMLBody = vbNewLine + incMess + objMail.HTMLBody Else incMess = "" Attachment1 = WebBrowser1.Document.all("txtList").Value Expires1 = WebBrowser1.Document.all("txtDate").Value preText = "------------------------------------" + vbNewLine + " Large Attachments " + vbNewLine posttext = vbNewLine + " Attachments added via filesharingserverindmz.cool " + vbNewLine + "powered by owners " + vbNewLine + "------------------------------------" filesAtt = Split(Attachment1, "|") For Each itm In filesAtt If itm <> "" Then ATTmsg = ATTmsg + "https://filesharingserverindmz.cool/get/" + itm + vbNewLine End If Next itm incMess = preText + ATTmsg + vbNewLine + "the attachments will be valid for " + Expires1 + " days from now" + vbNewLine + posttext objMail.Body = vbNewLine + incMess + objMail.Body End If Unload Me End If Exit Sub MessageACT: MsgBox "This button only works when composing email messages" End Sub Private Sub CommandButton2_Click() incMess = "" Attachment1 = WebBrowser1.Document.all("txtList").Value Expires1 = WebBrowser1.Document.all("txtDate").Value preText = "------------------------------------<br><b>Large Attachments</b><br>" + vbNewLine posttext = vbNewLine + "<br><font size=1>Attachments added via filesharingserverindmz.cool <br> powered by UNICEF Geneva ITSSD </font><br>------------------------------------" filesAtt = Split(Attachment1, "|") For Each itm In filesAtt If itm <> "" Then ATTmsg = ATTmsg + "<a href='https://filesharingserverindmz.cool/get/" + itm + "'>https://filesharingserverindmz.cool/get/" + itm + "</a><br>" + vbNewLine End If Next itm incMess = preText + ATTmsg + vbNewLine + "<br>the attachments will be valid for <b>" + Expires1 + "</b> days from now" + vbNewLine + posttext LargeAttachments.WebBrowser1.Document.Body.innerHTML = "<body><font style='font-size:11px'>" + incMess + "</font></body>" LargeAttachments.Show End Sub Private Sub CommandButton3_Click() WebCode1.Visible = True CommandButton2.Visible = True CommandButton1.Visible = False WebBrowser1.Visible = False WebCode1.Navigate2 "https://filesharingserverindmz.cool/uploader/upload/plugin/upload.php" incMess = "" Attachment1 = WebBrowser1.Document.all("txtList").Value Expires1 = WebBrowser1.Document.all("txtDate").Value preText = "------------------------------------<br><b>Large Attachments</b><br>" + vbNewLine posttext = vbNewLine + "<br><font size=1>Attachments added via filesharingserverindmz.cool <br> powered by UNICEF Geneva ITSSD </font><br>------------------------------------" filesAtt = Split(Attachment1, "|") For Each itm In filesAtt If itm <> "" Then ATTmsg = ATTmsg + "<a href='https://filesharingserverindmz.cool/get/" + itm + "'>https://filesharingserverindmz.cool/get/" + itm + "</a><br>" + vbNewLine End If Next itm incMess = preText + ATTmsg + vbNewLine + "<br>the attachments will be valid for <b>" + Expires1 + "</b> days from now" + vbNewLine + posttext WebCode1.Document.Body.innerHTML = "<html><body><font style='font-size:11px'>" + incMess + "</font></body></html>" WebCode1.SetFocus End Sub Private Sub UserForm_Activate() LargeAttachments.WebBrowser1.Navigate2 "about:blank" WebBrowser1.Navigate2 "https://filesharingserverindmz.cool/uploader/upload/plugin/upload.php" End Sub 



in the code above
- filesharingserverindmz.cool - the domain on which the PLUpload-a PHP script is hosted
- CommandButton1 - Attach button
- WebBrowser1 - WebBrowser control
- LargeAttachments - form name

Next, create a module, and paste this into it:
 Sub Attachment() LargeAttachments.Show End Sub 


Next, we connect this macro to the toolbar as a button (attention! To the toolbar that appears when creating a letter, and not to the general one)
It turns out something like this:


It is quite convenient to use, here is an example video:




And yet, this is not a ready-made solution and for implementation it is necessary to finish it significantly. The purpose of the article was to show the idea itself and illustrate with an example of implementation

Source: https://habr.com/ru/post/204708/


All Articles