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 in Microsoft Outlook 2010 (I think from 2013 it will work too).
So, the initial conditions:
- MS Exchange Server 2010 - inhouse - there is no admin admin - the author is just a user
- Limitations on the total volume of emails 10Mb
- There are a couple of Linux web servers in your DMZ and admin access to the corporate intranet
You need to:
- Organize a convenient transfer mechanism large files (very large)
- Do not use third-party providers to store information The
first thought was to use services such as dropbox, or rather their self-hosted counterparts like ownCloud. However, deploying it all just for attachments seemed inadequate.
In addition, how to attach inside Outlook is still unclear. An option with plugins is more suitable here, such as what YouSendIt and other similar services for example offer . It looks like this: in Outlook a button appears when clicking on which the service window pops up and our large attachment file is uploaded, when the download is complete, a link to it is generated and inserted into the body of the message. Since we cannot use services of this type, and accordingly their plugins, we will do their analogue.
Stage 1. The online file sharing service.
It's quite 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 verified (with the support of SSO authentication) through the corporate intranet, approximately as described here
- when the file is downloaded successfully, the generated URL for downloading it is added to the invisible txtList element (why this will be necessary from the next step)
- I also added cron to delete old links - in order to save disk space
Size limits depend on the settings of PHP and the web server, I set a limit of 2 GB per file (I can attach up to 10 files at a time).
Stage 2. Client part
Ideally it should be an Outlook Plug-in, but as far as I understand plug-ins are not so easy to make and so far I will not spend time on this ...
Instead, I made a regular VBA project and screwed it to the toolbar in Outlook.
The project consists of a form on which are placed:
- the standard button with the Attach heading
- the standard WebBrowser control (actually the IE frame)
It looks like this
Next is the code for this all in Visual Basic, I apologize in advance if it seems to someone not comme il faut, I don’t absolutely a programmer (not a VB programmer - that's for sure)
in the code above
- filesharingserverindmz.cool - the domain on which the PHP script is hosted PLUpload-a
- CommandButton1 - Attach button
- WebBrowser1 - control WebBrowser
- LargeAttachments - form name
Next, create a module, and paste this into it:
Next, we connect this macro to the toolbar in the form of a button (attention! To the toolbar that appears when you create the letter, and not to the general one)
It turns out something like this:
Use is quite convenient, here is an example video:
And yet, this is not a ready-made solution and for implementation it is necessary to significantly finish it. The purpose of the article was to show the idea itself and illustrate it with an implementation example.
So, the initial conditions:
- MS Exchange Server 2010 - inhouse - there is no admin admin - the author is just a user
- Limitations on the total volume of emails 10Mb
- There are a couple of Linux web servers in your DMZ and admin access to the corporate intranet
You need to:
- Organize a convenient transfer mechanism large files (very large)
- Do not use third-party providers to store information The
first thought was to use services such as dropbox, or rather their self-hosted counterparts like ownCloud. However, deploying it all just for attachments seemed inadequate.
In addition, how to attach inside Outlook is still unclear. An option with plugins is more suitable here, such as what YouSendIt and other similar services for example offer . It looks like this: in Outlook a button appears when clicking on which the service window pops up and our large attachment file is uploaded, when the download is complete, a link to it is generated and inserted into the body of the message. Since we cannot use services of this type, and accordingly their plugins, we will do their analogue.
Stage 1. The online file sharing service.
It's quite 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 verified (with the support of SSO authentication) through the corporate intranet, approximately as described here
- when the file is downloaded successfully, the generated URL for downloading it is added to the invisible txtList element (why this will be necessary from the next step)
- I also added cron to delete old links - in order to save disk space
Size limits depend on the settings of PHP and the web server, I set a limit of 2 GB per file (I can attach up to 10 files at a time).
Stage 2. Client part
Ideally it should be an Outlook Plug-in, but as far as I understand plug-ins are not so easy to make and so far I will not spend time on this ...
Instead, I made a regular VBA project and screwed it to the toolbar in Outlook.
The project consists of a form on which are placed:
- the standard button with the Attach heading
- the standard WebBrowser control (actually the IE frame)
It looks like this
Next is the code for this all in Visual Basic, I apologize in advance if it seems to someone not comme il faut, I don’t absolutely a programmer (not a VB programmer - that's for sure)
VBA project code
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 + "
Attached" + Attachment1
incMess = ""
Attachment1 = WebBrowser1.Document.all("txtList").Value
Expires1 = WebBrowser1.Document.all("txtDate").Value
preText = "------------------------------------
Large Attachments
" + vbNewLine
posttext = vbNewLine + "
Attachments added via filesharingserverindmz.cool
powered by owners
-------------------"
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.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 = "------------------------------------
Large Attachments
" + vbNewLine
posttext = vbNewLine + "
Attachments added via filesharingserverindmz.cool
powered by UNICEF Geneva ITSSD
------------------------------------"
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
LargeAttachments.WebBrowser1.Document.Body.innerHTML = "" + incMess + ""
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 = "------------------------------------
Large Attachments
" + vbNewLine
posttext = vbNewLine + "
Attachments added via filesharingserverindmz.cool
powered by UNICEF Geneva ITSSD
------------------------------------"
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
WebCode1.Document.Body.innerHTML = "" + incMess + ""
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 PHP script is hosted PLUpload-a
- CommandButton1 - Attach button
- WebBrowser1 - control WebBrowser
- 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 in the form of a button (attention! To the toolbar that appears when you create the letter, and not to the general one)
It turns out something like this:
Use is quite convenient, here is an example video:
And yet, this is not a ready-made solution and for implementation it is necessary to significantly finish it. The purpose of the article was to show the idea itself and illustrate it with an implementation example.