01/11/2012

WSS Emailing Itself -: x-mailer: Windows SharePoint Services (version 3)

I had a case recently where a client wanted to send access request emails to an email enabled document library. We encountered the problem of WSS not being able to handle the x-mail header.
A solution was to create a vbscript that fired when an email entered the 'Drop' folder of IIS mailroot and stripped out the problematic header.
Initial testing proved successfull and this has now been implemented.
solution
1. copy Smtpreg.vbs into the c:\inetpub\AdminScripts - smtpreg is available to download from MS.

2. create a vbs file from the script below and copy it to the AdminScripts folder (I named mine wss)

<SCRIPT LANGUAGE="VBScript">


Sub ISMTPOnArrival_OnArrival(ByVal iMsg, EventStatus )

if iMsg.Fields("urn:schemas:mailheader:x-mailer") = "Windows SharePoint Services (version 3)" then
iMsg.Fields.Delete("urn:schemas:mailheader:x-mailer")
iMsg.Fields.Update
end if

iMsg.DataSource.Save
EventStatus = 0
End Sub




3. run the following commands to register the script

cd c:\inetpub\adminscripts
cscript smtpreg.vbs /add 1 OnArrival DeleteMsg CDO.SS_SMTPOnArrivalSink "mail from=*"
cscript smtpreg.vbs /setprop 1 OnArrival DeleteMsg Sink ScriptName "c:\Inetpub\AdminScripts\wss.vbs"

4. This will now catch all mail on arrival and remove the offending header.


26 comments:

  1. Where is the script code?

    ReplyDelete
  2. Really can you post the script that should be under #2? I'm having the exact same problem and would really like to see how youv'e done this. Thanks!!!

    ReplyDelete
  3. I also need this Script code. It would be of great help to us. THX

    ReplyDelete
  4. <script language="VBScript">
    Sub ISMTPOnArrival_OnArrival(ByVal iMsg, EventStatus )
    'Check for Sharepoint x-mailer header
    if iMsg.Fields("urn:schemas:mailheader:x-mailer") = "Windows SharePoint Services (version 3)" then
    'Delete the offending line
    iMsg.Fields.Delete("urn:schemas:mailheader:x-mailer")
    'Update the mail header
    iMsg.Fields.Update
    end if

    'Save changes to the mail
    iMsg.DataSource.Save

    'Continue execution of the next sink
    EventStatus = 0
    End Sub
    </script>

    ReplyDelete
  5. You can find the above code if you view source the page (IE hides it!). I added the comments to try to help.
    Ian

    ReplyDelete
  6. Wonderful! Thanks a lot. I did not know, that it is possible to register an event sink at the SMTP-service.

    ReplyDelete
  7. thank you, thank you, thank you. I spent a full day troubleshooting this.

    ReplyDelete
  8. I tried to implement the above by following the steps: copy smtpreg.vsb from Microsoft, and I created the wss.vsb using the script above however - I am not getting the desired results. X-Mailer: Windows SharePoint Services (version 3) still remains in the .eml file. Is there an additional step outside of running the commands to register the script? Thanks!

    ReplyDelete
  9. Hi
    there is no additional step.
    Can you post your code on here so I can take a look at it

    ReplyDelete
  10. I am just pasting in this guy to create the wss.vsb script:

    Sub ISMTPOnArrival_OnArrival(ByVal iMsg, EventStatus )

    if iMsg.Fields("urn:schemas:mailheader:x-mailer") = "Windows SharePoint Services (version 3)" then
    iMsg.Fields.Delete("urn:schemas:mailheader:x-mailer")
    iMsg.Fields.Update
    end if

    iMsg.DataSource.Save
    EventStatus = 0
    End Sub

    And I am getting the smtpreg.vbs script from Microsoft:
    http://msdn.microsoft.com/en-us/library/ms528023(v=exchg.10).aspx

    My emails appear in the /Drop folder - so nothing on the surface seems out of whack. I just am not able to strip out the X-Mailer header.

    Thanks again for the code and the help.

    ReplyDelete
  11. are you saving this as .vbs or .vsb ?

    It should be vbs

    ReplyDelete
  12. .vbs - sorry, poor typing in the earlier post. And to clarify this MOSS 2007 with WSS 3, and the most recent cumulative update from Microsoft.

    No errors get kicked back while registering the scripts in the command prompt either.

    Thanks

    ReplyDelete
  13. Hi...and the name of your vbs file?

    ReplyDelete
  14. Same thing as posted above: Smtpreg.vbs and wss.vbs

    ReplyDelete
  15. How would you change this to work with SharePoint 2010? I assume the "Windows SharePoint Services (version3)" line needs to change, but I'm not sure what to change it to.

    How do you make it so you can see the messages in transit to know what the fields and data look like?

    Toby Hosterman
    toby@natpain.com

    ReplyDelete
  16. Hi Toby
    You will have to capture one of the emails in the c:\\inetpub\mailroot\drop\ folder.

    Open it up with notepad and see what the mailheader says.

    ReplyDelete
  17. Nevermind, I got it working by tweaking wss.vbs a little as follows, hopefully making it SharePoint version independent:

    <_SCRIPT LANGUAGE="VBScript">


    Sub ISMTPOnArrival_OnArrival(ByVal iMsg, EventStatus )

    if instr(iMsg.Fields("urn:schemas:mailheader:x-mailer"),"SharePoint") > 1 then
    iMsg.Fields.Delete("urn:schemas:mailheader:x-mailer")
    iMsg.Fields.Update
    end if

    iMsg.DataSource.Save
    EventStatus = 0
    End Sub




    Toby Hosterman
    toby@natpain.com

    ReplyDelete
  18. great stuff.....glad the script helped a little

    ReplyDelete
  19. Are there any services that must be restarted for this to take affect?

    ReplyDelete
  20. Does this solution require MS Exchange server to be running or will it work with the SMTP Server that comes with IIS 6?

    ReplyDelete
  21. the script is for the local smtp service

    ReplyDelete
  22. Thank you for this -- worked great!!!

    ReplyDelete
  23. Trying to do this in our new SharePoint 2013 environment but the smptreg script keeps failing...getting a Permission Denied even with an elevated cmd screen. Also says "have you registered your sink COM class on this machine" which I haven't been able to find anything on.....

    ReplyDelete
  24. Great article ...Thanks for your great information, the contents are quiet interesting.
    SharePoint Training
    SharePoint Online Training

    ReplyDelete
  25. Use the article below if you get access denied:
    https://blog.vamsoft.com/2009/12/12/smtp-event-sinks-under-windows-server-2008-r2/

    ReplyDelete