Remote File Access Through E-Mail
Blog | Tech Blog | Secure Coding | Twitter | RSS Feed | Get Email Updates
| Download: | shantz-outlook-remote-file |
|---|---|
| Version: | 0.1 |
| Updated: | August 30, 2008 |
| Size: | 1.19 KB |
| Hits: | 1,369 |
Introduction:
This is a (proof-of-concept) outlook macro that you can use with an outlook rule to retrieve your files from your home/office PC by sending it a mail with a subject having a predefined special keyword and the body containing the names and paths of the files. The remote PC will then mail you the files on a predefined e-mail ID.
This project came into being after reading this post at lifehacker (original post and solution here). It listed a method to retrieve mails on your home/office PC by sending a “magic email” to it, but it was only for mac’s. Seeing that people wanted it for windows as well, I thought of making something up during lunch time at office.
Usage:
1. Download the attached zip file (shantz-outlook-remote-file-access.zip) and unzip it. It has a VB module “shantz-outlook-remote-file-access.bas” (can be opened with any text editor)
2. Create a new macro in Outlook. Copy the code contained in Module1.bas to the main source file of the macro.
3. Edit the code to change the e-mail ID to which the files will be e-mailed. Save the macro.
4. Create a new rule in Outlook. Choose to run the rule when a specific word is found in the subject. e.g. use “SendMeMyFiles”.
5. The action part of the rule should be “run a script”. Here you can choose the macro that you just created from the list shown by Outlook.
6. Save the rule and you are done.
Now try, sending a mail to the account that your outlook is configured to receive mail for, with the special keyword in the subject and a list of files (with their complete absolute paths on the remote computer) separated by semicolons (”;” without the quotes), and watch magic happen
.
e.g.: To: myemail@email.com
subject: SendMeMyFiles
Body: c:\path\of\files\file1;d:\second\path\file2
IMPORTANT NOTES:
- For this thing to work, outlook has to be running on the remote PC as this depends on a “client-side” rule.
- This is just a proof-of-concept as of now, so there is no error handling right now. Plus the e-mail body parsing is finicky and so the e-mail body should not have anything other than the file paths and names. This might change in future if I decide to update it.
- Don’t use it if your life depends on it. Use it for basic purposes and modify and improve it appropriately before you decide to use it seriously (You may submit your modifications here as well)
- It has been tested only on Outlook 2003, but might work on others as well.
Let me know of any thoughts you may have about this.
© Shantanu Goel | Remote File Access Through E-Mail
|
Liked this post? Get FREE Updates Subscribe to RSS feed |







This post has 21 comments
February 20th, 2008
fundooo!!!!
Thats cool !
February 20th, 2008
thnx rohit
February 21st, 2008
When you set up the macro in Outlook, I’m assuming you set up a new macro name, I used ‘remote’
So then you you hit create and you get the following code:
Sub remote()
End Sub
Are you supposed to paste your code in between the sub and end sub? Like so:
Sub remote()
Attribute VB_Name = “Module1″
Function mail(strTo As String, _
strSubject As String, _
strMessageBody As String, _
Optional strAttachments As String) As Boolean
Dim MAPISession As Outlook.NameSpace
Dim MAPIFolder As Outlook.MAPIFolder
Dim MAPIMailItem As Outlook.MailItem
Dim oRecipient As Outlook.Recipient
Dim TempArray() As String
Dim varArrayItem As Variant
Dim blnSuccessful As Boolean
Set MAPISession = Application.Session
If Not MAPISession Is Nothing Then
MAPISession.Logon , , True, False
Set MAPIFolder = MAPISession.GetDefaultFolder(olFolderOutbox)
If Not MAPIFolder Is Nothing Then
Set MAPIMailItem = MAPIFolder.Items.Add(olMailItem)
If Not MAPIMailItem Is Nothing Then
With MAPIMailItem
TempArray = Split(strTo, “;”)
For Each varArrayItem In TempArray
Set oRecipient = .Recipients.Add(CStr(Trim(varArrayItem)))
oRecipient.Type = olTo
Set oRecipient = Nothing
Next varArrayItem
.Subject = strSubject
If StrComp(Left(strMessageBody, 6), “”, vbTextCompare) = 0 Then
.HTMLBody = strMessageBody
Else
.Body = strMessageBody
End If
TempArray = Split(strAttachments, “;”)
For Each varArrayItem In TempArray
varArrayItem = CStr(moreTrim(varArrayItem))
.Attachments.Add varArrayItem
Next varArrayItem
.Send
Set MAPIMailItem = Nothing
End With
End If
Set MAPIFolder = Nothing
End If
MAPISession.Logoff
End If
blnSuccessful = True
End Function
Public Function moreTrim(ByVal sValue As String) As _
String
Dim sAns As String
Dim sWkg As String
Dim sChar As String
Dim lLen As Long
Dim lCtr As Long
sAns = sValue
lLen = Len(sValue)
If lLen > 0 Then
For lCtr = 1 To lLen
sChar = Mid(sAns, lCtr, 1)
If Asc(sChar) > 32 Then Exit For
Next
sAns = Mid(sAns, lCtr)
lLen = Len(sAns)
If lLen > 0 Then
For lCtr = lLen To 1 Step -1
sChar = Mid(sAns, lCtr, 1)
If Asc(sChar) > 32 Then Exit For
Next
End If
sAns = Left$(sAns, lCtr)
End If
moreTrim = sAns
End Function
Sub intercept(MyMail As MailItem)
Dim strID As String
Dim objNS As Outlook.NameSpace
Dim objMail As Outlook.MailItem
Dim replyto As String
Dim result As Boolean
Dim file As String
strID = MyMail.EntryID
Set objNS = Application.GetNamespace(”MAPI”)
Set objMail = objNS.GetItemFromID(strID)
file = objMail.Body
result = mail(”abc@abc.com”, file, “”, file)
End Sub
End Sub
?????
If so, there are syntax errors when I try and call the macro … please help!
February 21st, 2008
Awesome. I will use this script to make outlook do other stuff for me.
February 21st, 2008
@llcooljayce:
You need to “replace” the default code that is present by the source code that I just gave. (Remove the top line which says Module “shantz-….”). Otherwise, you can delete the default file that is there and import the file that I gave…
February 21st, 2008
@JJMelo: thnx. Do send me a word if you do any modifications
February 21st, 2008
Really very cool!! Nice job!!
February 21st, 2008
thnx pradeep
February 21st, 2008
Or, you could just use this free program…
http://www.runtime.org/remotebymail.htm
February 21st, 2008
@Steven: yeah, the solution is just one amongst the sea of others available
, some might find it useful because they can’t use other methods because of restrictions (e.g. installing new softwares)….
March 5th, 2008
Great website!! Keep up the good work!!
March 12th, 2008
cool concept! Could it be re-written to place a file on a computer in a specific folder?
March 12th, 2008
@jack, yes, it can be rewritten for that..infact it can be modified to do a lot of things, like even shutting down/restarting your computer, running external programs, even modifying files, and what not. Only limitations are:1. How far can you imagine
2. How much you know (or are willing to learn) about outlook macro scripting.
April 18th, 2008
Great idea. Problem is I would rarely remember the full path of the file.
I think this could be enhanced by asking for a text file oitlining the folder structure first.
For example:
Subject: MailFolderList
C:\ProjectFolder
The result would be a .txt file with all folders and files in it. Then you could execute the retrieve file email.
April 18th, 2008
Yes Jason, you are absolutely right about that. This is just a proof of concept. Basically how I would build on it is that the subject would always remain the same, but the body can contain “commands” followed by arguments and may even contain multiple commands. So u can say smthing like:
shell:dir >c:\files.txt
mailback: c:\files.txt
May 2nd, 2008
wow….thanks for the download file. it’s very helpful.
May 2nd, 2008
arejae, glad you liked it.
May 10th, 2008
i am using and it work nicely.
August 21st, 2008
I’ve done something similar, but instead,I’ve only used the subject line. I had a ruby script that the macro would call and send it the subject line, so the only work the macro did was to determine if it was the “magic’. This was denoted by the subject line starting with spawn task:xxxxxxx, replyemailaddress. Where xxxxx was one of the verbs that the ruby script expected. The ruby script would perfomr the task and email the result. Tasks were reports on status of certain systems. (dbase up, stage, test environments up, restart stage, test environments). Unfortunatlly MS did not allow for reading the senders email, that way I could respond to the sender, hence the replyemail param. the ruby script would only reply if the domain was one of the allowed few.
September 14th, 2008
i use 2 resive my all e-mail on outlook at my desktop . one day i have use control Import/Export by this my all inbox mail have delete from from my mail id on Net . but it is present on my Desktop in outlook.
so plz tell me how can i send my mail 2 agian at my mail on Enternet
plz help me out before i formate my system.
one more thing i copy outlook folder in other plase but it is not opening . so also tell me how can i open that outlook file ????
plz send me all mail about this prob on drsharmamahesh@rediffmail.com
February 18th, 2009
can i use the script for downloading file from the internet via e-mail?
because in my office, i cant download file bigger than 2 MB via browser or download manager. But if the file is an attachment in e-mail, i can download it.
Trackbacks