Post new topic Reply to topic  [ 15 posts ] 
Author Message
 Post subject: E-mail Drop Folder for Sharepoint
PostPosted: 2012-11-08 00:13 
Normal user
User avatar

Joined: 2012-03-29 17:25
Posts: 116
Location: Kansas City
Salvete! I have two servers - one hosts Sharepoint and Active Directory, the other hosts hMailServer. I want to configure Sharepoint to receive incoming email. In the sharepoint settings (SCA), I can point to an "Email Drop Folder" where sharepoint will pick up its incoming mail.

Each sharepoint library can have its own email address.

Now, do I configure sharepoint to look in hmailserver's data folder for email? I suppose that I have to create an email account in hmailserver for each sharepoint-email-enabled library, no?

Or can I configure hmailserver to deliver its email to a folder on sharepoint's server?

Has anyone ever done this?


Top
 Profile  
 
 Post subject: Re: E-mail Drop Folder for Sharepoint
PostPosted: 2012-11-08 01:50 
Moderator
User avatar

Joined: 2007-06-14 05:12
Posts: 9358
Location: 'The Outback' Australia
brother.gabriel wrote:
Now, do I configure sharepoint to look in hmailserver's data folder for email? I suppose that I have to create an email account in hmailserver for each sharepoint-email-enabled library, no?

No don't do that. That will confuse hMailserver and make it fail. It will probably also overload sharepoint and make it fail too.
brother.gabriel wrote:
Or can I configure hmailserver to deliver its email to a folder on sharepoint's server?

You can create a script that saves a copy of a message in a known location.
brother.gabriel wrote:
Has anyone ever done this?

Yes, I have.

If hMailserver and sharepoint are on separate machines, you could also setup IIS SMTP to handle the pickup and drop

_________________
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
Documentation


Top
 Profile  
 
 Post subject: Re: E-mail Drop Folder for Sharepoint
PostPosted: 2012-11-08 03:17 
Normal user
User avatar

Joined: 2012-03-29 17:25
Posts: 116
Location: Kansas City
Thanks, Matt.

I found these, which are very pertinent, and seem very good - AND by folks who are actually using hMailServer with Sharepoint! Imagine finding a tutorial like that!

http://johanolivier.blogspot.com/2011/0 ... -mail.html
http://weblogs.asp.net/wesleybakker/arc ... point.aspx

I'm going to take a good try here and I'll let y'all know how it goes.


Top
 Profile  
 
 Post subject: Re: E-mail Drop Folder for Sharepoint
PostPosted: 2012-11-08 03:42 
Normal user
User avatar

Joined: 2012-03-29 17:25
Posts: 116
Location: Kansas City
Okay, having looked at those pages, I have some questions.

First, I am already using my domain for email, and my sharepoint portal uses the same domain.
Say, my email address is admin@mydomain.org
And my portal is at portal@mydomain.org

I have already set up Sharepoint (on my other server) to use hMailserver for SMTP (by configuring the other server's iis6). That works.

Now, Sharepoint is pointed at a drop folder on its own server.f
DNS routes all mail to hMailServer.

Also, Sharepoint can have LOTS of email addresses. How can I make sure they all work? Do I have to create an account for each one in order to receive the mail from the outside world?

Also, if hMailserver drops its mail into the drop folder, how does Sharepoint know which messages are for which list? Can it tell from the addressing? If I dropped ALL mail into the dropfolder, would Sharepoint just pick out the messages that were pertinent to its configured lists?

From one of the links I posted above, there is a script for adding the appropriate headers, and for copying messages to the drop folder. However, my drop folder is on the other server. How do I authenticate that?

Here is the script for delivery to the drop folder:

Code:
Sub OnDeliverMessage(oMessage)
        Dim path, filename, fso, original, copy

    path = Split(oMessage.Filename, "\", -1, 1)

    filename = "C:\Program Files (x86)\hMailServer\Data\development.com\dropfolder\" & _
           path(UBound(path))

    Set fso = CreateObject("Scripting.FileSystemObject")

    Set copy = fso.CreateTextFile(filename, True)
        copy.WriteLine("x-sender: " & oMessage.FromAddress)
        copy.WriteLine("x-receiver: " & oMessage.To)

    Set original = fso.OpenTextFile(oMessage.Filename, 1)
        copy.WriteLine(original.ReadAll)
       
    copy.Close
    original.Close
End Sub


Top
 Profile  
 
 Post subject: Re: E-mail Drop Folder for Sharepoint
PostPosted: 2012-11-08 03:56 
Normal user
User avatar

Joined: 2012-03-29 17:25
Posts: 116
Location: Kansas City
I suppose that if I prepend all my sharepoint list email addresses with "portal_" then I could, in the hMailServer script, parse the addresses and only copy to the drop folder those messages with the prefix.


Top
 Profile  
 
 Post subject: Re: E-mail Drop Folder for Sharepoint
PostPosted: 2012-11-08 04:38 
Moderator
User avatar

Joined: 2007-06-14 05:12
Posts: 9358
Location: 'The Outback' Australia
yes, that's the approach I'd use in your circumstances...

I actually created a new local only domain for my sharepoint, which then only allowed emails from local authenticated users (because no-one else could find it :) )

_________________
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
Documentation


Top
 Profile  
 
 Post subject: Re: E-mail Drop Folder for Sharepoint
PostPosted: 2012-11-08 04:55 
Normal user
User avatar

Joined: 2012-03-29 17:25
Posts: 116
Location: Kansas City
I would do that, except that not all the users are local.


Top
 Profile  
 
 Post subject: Re: E-mail Drop Folder for Sharepoint
PostPosted: 2012-11-08 05:04 
Normal user
User avatar

Joined: 2012-03-29 17:25
Posts: 116
Location: Kansas City
Now, if I have many sharepoint lists, that means I have to create an account for each list, right? Is there a workaround?


Top
 Profile  
 
 Post subject: Re: E-mail Drop Folder for Sharepoint
PostPosted: 2012-11-08 06:37 
Moderator
User avatar

Joined: 2007-06-14 05:12
Posts: 9358
Location: 'The Outback' Australia
no I don't think there is a workaround

I think you need an account each list - certainly in sharepoint you do.
perhaps in hmailserver you could use + addressing, I'm not certain though

_________________
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
Documentation


Top
 Profile  
 
 Post subject: Re: E-mail Drop Folder for Sharepoint
PostPosted: 2012-11-08 17:01 
Normal user
User avatar

Joined: 2012-03-29 17:25
Posts: 116
Location: Kansas City
Okay, I got hmailserver to copy mail to a temp folder based on the prefix of the address, so if the TO address contains "portal_" at its start, hms will copy the mail to the temp folder.

Now, I have a function that copies that message to sharepoint's drop folder on the other server. Problem is, that the function fails. If I put the copy-file function in its own vbs file and run it by double clicking on the file, it works. But if I call the function from within the hms eventhandler script, it fails - that is, it says it can't find the destination folder. But the very same function works perfectly if not called from hmailserver.

Is there something I am missing?


Top
 Profile  
 
 Post subject: Re: E-mail Drop Folder for Sharepoint
PostPosted: 2012-11-08 17:51 
Normal user
User avatar

Joined: 2012-03-29 17:25
Posts: 116
Location: Kansas City
Now, hmailserver is running on the local system account. Maybe that account doesn't have rights to run wscript shell objects from vbs files? If I run the vbs myself it works, but I am admin. That is the only thing I can think of that could be the problem.

Problem is that hmailserver NEEDS to run on the system account - that is, it needs to run even if nobody is logged in. How can I give rights to just hmailserver to run shell commands?


Top
 Profile  
 
 Post subject: Re: E-mail Drop Folder for Sharepoint
PostPosted: 2012-11-08 23:43 
Normal user
User avatar

Joined: 2012-03-29 17:25
Posts: 116
Location: Kansas City
Okay, now I finally got it to copy the messages to the Sharepoint drop folder (I had to use the script to map the drive to a share folder - I wish I didn't have to do that, but it seems to work).

Now I can see the messages getting delivered, and after a few moments, Sharepoint removes them from the drop folder. (next problem is, why don't they go into the list..., but that is no longer an hMailServer issue, so my thread ends here.)

By the way, here is my code for copying the messages to the other machine:


Code:
   function CopyFileToRemoteMachine(whatMachine, whatUsername, whatPassword, whatSourceFile, whatDestination)
      dim errormessage, mdrive
      errormessage    = "File successfully copied"

      mdrive = "N:"

      Dim objFSO, objNetwork
      Set objFSO = CreateObject("Scripting.FileSystemObject")
      Set objNetwork = CreateObject("Wscript.Network")

      If not objFSO.FileExists(mdrive)  Then
         objNetwork.MapNetworkDrive mdrive, whatDestination, False, whatUsername, whatPassword
      End If

      If Right(whatDestination, 1) <> "\" Then
           whatDestination = whatDestination & "\"
      End If
      If objFSO.FileExists(whatSourceFile) Then
           If objFSO.FolderExists(whatDestination) Then
            objFSO.CopyFile whatSourceFile, whatDestination, True
           Else
               errormessage = "Destination does not exist: " & whatDestination
           End If
      Else
           errormessage = "Source file does not exist: " & whatSourceFile
      End If

      objNetwork.RemoveNetworkDrive mdrive,TRUE,TRUE

      set objFSO = nothing
      set objNetwork = nothing

      CopyFileToRemoteMachine = errormessage
   end function


Top
 Profile  
 
 Post subject: Re: E-mail Drop Folder for Sharepoint
PostPosted: 2012-11-09 00:46 
Normal user
User avatar

Joined: 2012-03-29 17:25
Posts: 116
Location: Kansas City
If anyone is still following this thread, I have an extensive post here dealing with Sharepoint issues.


Top
 Profile  
 
 Post subject: Re: E-mail Drop Folder for Sharepoint
PostPosted: 2012-11-09 01:39 
Moderator
User avatar

Joined: 2007-06-14 05:12
Posts: 9358
Location: 'The Outback' Australia
I am pretty sure that on a separate server that I used IIS SMTP to receive the mails for sharepoint, which then put them in the default IIS SMTP drop folder, which sharepoint then picked up. I set a route in hMailserver to point to the IP address of that other server.

You are correct above in your assessment of why the save to network folder didn't work - it is the user that hMailserver runs under. Mapping the network path every time the script is run is an interesting but valid solution. Alternately you could have changed the user to one that already has the network path mapped.

Good work, thanks for the followup and the detailed set of steps.

_________________
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
Documentation


Top
 Profile  
 
 Post subject: Re: E-mail Drop Folder for Sharepoint
PostPosted: 2012-11-09 05:02 
Normal user
User avatar

Joined: 2012-03-29 17:25
Posts: 116
Location: Kansas City
Matt, thanks for the thanks! I really like hMailServer, and am pleased to contribute! I am also pleased that there be folks here to read my rants and keep me going.

Now, I'd rather not have to map the server (and unmap it) for every email, and would rather use a different user account. Problem is that hMailServer needs to run as a service when noone is logged on.
Quote:
I used IIS SMTP to receive the mails for sharepoint

I don't understand that - SMTP is just for sending mail, no? I do understand that I need the iis6 "virtual server" in order for sharepoint to send mail using hMailserver SMTP (at least, that's how I've gotten it to work).

However, that SMTP drop folder (in inetpug/mail) is exactly where my script is dumping the Sharepoint mail.

Quote:
I set a route in hMailserver to point to the IP address of that other server.

Matt, could you explain that a little for me?

By the way, to be truly complete, here is my function for sifting for sharepoint-mail.
If I make all the sharepoint-destined mail to be prepended with "portal_" then I have a way to send ONLY sharepoint-destined mail to the dropfolder for transfer.
In this example, I copy the messages to a folder outside hMailserver's data folder, and then transfer it to the other server using the function I showed in the previous post.

Code:
sub CopyMessageToSharepointDropFolder(oMessage)
   'x-sender and x-receiver are necessary for sharepoint
   'see also http://weblogs.asp.net/wesleybakker/archive/2010/08/09/configure-hmailserver-for-sharepoint.aspx
   
   dim SPdropfolder
   dim SPprefix
   SPdropfolder = "c:\hMailServer\sharepointDropFolder\"
   SPprefix = "portal_"
   '------------------------
   dim SPprefixLen, toaddress
   SPprefixLen= len(SPprefix)
   toaddress = oMessage.To
   if left(toaddress, SPprefixLen) = SPprefix Then
      write_log ("  Copying mail to Sharepoint Drop Folder")
      
      Dim path, mailfilename, fso, original, mailfile
      path = Split(oMessage.Filename, "\", -1, 1)
      mailfilename = SPdropfolder & path(UBound(path))
      Set fso = CreateObject("Scripting.FileSystemObject")
      
      Set mailfile = fso.CreateTextFile(mailfilename, True)
         mailfile.WriteLine("x-sender: " & oMessage.FromAddress)
         mailfile.WriteLine("x-receiver: " & oMessage.To)
      Set original = fso.OpenTextFile(oMessage.Filename, 1)
         mailfile.WriteLine(original.ReadAll)     
      mailfile.Close
      original.Close   
      
      dim SPcopyMessage
      SPcopyMessage = CopyFileToRemoteMachine("SERVER", "domain\hMailServer", "password", mailfilename, "\\SERVER\portalmail\drop")
      write_log("   Sharepoint Drop Message Status: " & SPcopyMessage)
   End If
   
end sub


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 15 posts ] 


Who is online

Users browsing this forum: No registered users and 4 guests



Search for:
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group