Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBScript Help Noobie I'm afraid 5

Status
Not open for further replies.

edzy55

MIS
Jul 12, 2001
103
GB
Hi All,

I'm using a vanilla M$ vbscriptM$ that stamps outgoing emails from our company with a disclaimer on our mail exchange mail server. The problem I have is, when someone gets in a convo with someone outside, the disclaimer is added everytime it's replying back out to. It's okay but would prefer if it only stamped it once and ignored the script if the email had the disclaimer content already.

Here's the script
<SCRIPT LANGUAGE="VBScript">
Sub ISMTPOnArrival_OnArrival(ByVal Msg, EventStatus)
TextDisclaimer = vbCrLf & "DISCLAIMER:" & vbCrLf & "Sample Disclaimer added in a VBScript."
HTMLDisclaimer = "<p></p><p>DISCLAIMER:<br>Sample Disclaimer added in a VBScript."

If Msg.HTMLBody <> "" Then
'Search for the "</body>" tag and insert our disclaimer before that tag.
pos = InStr(1, Msg.HTMLBody, "</body>", vbTextCompare)
szPartI = Left(Msg.HTMLBody, pos - 1)
szPartII = Right(Msg.HTMLBody, Len(Msg.HTMLBody) - (pos - 1))
Msg.HTMLBody = szPartI + HTMLDisclaimer + szPartII
End If

If Msg.TextBody <> "" Then
Msg.TextBody = Msg.TextBody & vbCrLf & TextDisclaimer & vbCrLf
End If

'Commit the content changes to the transport ADO Stream object.
Msg.DataSource.Save ' Commit the changes into the transport Stream

EventStatus = cdoRunNextSink
End Sub
</SCRIPT>

Be great if somewhere in the script it could be added if disclaimer exists in email, goto end or something. It may already be their, just need a pointer if so or code to be added to this effect.

Hope someone can help, many thanks.


Edzy55..........
 
If Msg.HTMLBody <> "" [!]And InStr(HTMLBody, HTMLDisclaimer) = 0 [/!]Then

If Msg.TextBody <> "" [!]And InStr(TextBody, TextDisclaimer) = 0 [/!]Then

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Wow PHV,

That was a very quick response, BIG thanks for getting back to me.

Quick question.
If Msg.HTMLBody <> "Would I put disclaimer text to look for here?" And InStr(HTMLBody, HTMLDisclaimer) = 0 Then

Also, doe's it matter where I place these lines to be at it's most efficient? Where would you place them in the script.

Thanks again, if this works I'll be eternally grateful :).

Edzy....


 
I rephrase my answer.
Replace this:
If Msg.HTMLBody <> "" Then
with this:
If Msg.HTMLBody <> "" And InStr(HTMLBody, HTMLDisclaimer) = 0 Then

and this:
If Msg.TextBody <> "" Then
with this:
If Msg.TextBody <> "" And InStr(TextBody, TextDisclaimer) = 0 Then

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks PHV,

I'm afraid that still didn't work, it keeps attaching the disclaimer I'm afraid.

Any other ideas.

Thanks,
 
They should be read like this.
[tt]If Msg.HTMLBody <> "" And InStr([red]Msg.[/red]HTMLBody, HTMLDisclaimer) = 0 Then[/tt]
[tt]If Msg.TextBody <> "" And InStr([red]Msg.[/red]TextBody, TextDisclaimer) = 0 Then[/tt]
 
tsuji You da man!

That seems to work a treat.

Thanks all for your help all. Hopefully this thread will help others out also.

Edzy55
 
Sorry to revisit this but it's actually not working. I left the site believing it was working, but in fact it still replicates the disclaimer when I came back to check.

Any ideas.

Thanks
 
This is the expected behavior of the event sink. The sink just monitors for SMTP email going out and adds the disclaimer. It does not check the contents of the message. You will not be able to do what you are looking to do while utilizing the event sink. Third party applications such as MIGHT offer you more options.

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
>It does not check the contents of the message

Erm ... well, it does as it looks for the closing </body> tag to determine where to correctly insert the HTML disclaimer. I'd certainly expect to be able to both read and modify the contents of the SMTP mail using this event sink (although not the MAPI-encapsulated variant that Outlook delivers to Exchange). And the fact that the OP says the dislaimer is being added shows that this bit is working as expected.
 
strongm, I think there is a big difference between looking for an end tag and doing a pattern match on custom messages configured in an event sink. In any event, each time the user sends the message back and forth, the closing body tag moves to the end of the message. The event sink detects that and adds the disclaimer again. The only way to avoid duplicates within the middle of the message is to educate users to remove it before sending.

Please note that this isn't MY OPINION. I'm sharing what I learned several years ago after following the same article from Microsoft and having initiated a call to MS Premier Support Services when I found the same annoying results.

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Thanks Strongm/markdmac.

Looks like it's a no go then & the coffin lid is nailed down here. Although very surprised it can't error or end using an if exist statement or something, I'm certainly no coder though.

Oh well, will probably use exclaimer or some 3rd party, would of been nice to do it without. Thanks guys for your help with this one, much appreciated.
 
I'm afraid that I am going to have to respectfully disagree with both you and Microsoft PSS, in that case Mark. I can (and do) happily carry out pattern matching in the event sink. For disclaimers, the normal problem is that the history in an email is normally indented or has other formatting or typographical elements (eg ">") applied to it to indicate that it is historical. So you can't do an (easy) exact match against a multiline disclaimer. So it is best to select a (hopefully) unique line from the disclaimer to check for.

This, for example, works and does exactly what I'd expect on my XP box:
Code:
[blue]<SCRIPT LANGUAGE="VBScript">
Sub ISMTPOnArrival_OnArrival(ByVal Msg, EventStatus)
   TextDisclaimer = vbCrLf & "DISCLAIMER:" & vbCrLf & "Sample Disclaimer added in a VBScript."
   HTMLDisclaimer = "<p></p><p>DISCLAIMER:<br>Sample Disclaimer added in a VBScript."


   If Msg.HTMLBody <> ""  and Instr(Msg.HTMLBody,"Sample Disclaimer added in a VBScript.")=0 Then
      'Search for the "</body>" tag and insert our disclaimer before that tag.
      pos = InStr(1, Msg.HTMLBody, "</body>", vbTextCompare)
      szPartI = Left(Msg.HTMLBody, pos - 1)
      szPartII = Right(Msg.HTMLBody, Len(Msg.HTMLBody) - (pos - 1))
      Msg.HTMLBody = szPartI + HTMLDisclaimer + szPartII
   End If

   If fred <> "" and Instr(fred,"Sample Disclaimer added in a VBScript.")=0 Then
      Msg.TextBody = fred & vbCrLf & TextDisclaimer & vbCrLf
   End If
    
   'Commit the content changes to the transport ADO Stream object.
   Msg.DataSource.Save ' Commit the changes into the transport Stream

   EventStatus =  0 'cdoRunNextSink
End Sub
</SCRIPT>[/blue]
 
Strongm, I don't have a system I can test that with, but it looks like it does not check for text only messages as well.

Congratulations to you if you have overcome the limitations of the original script.

And if it works with an Exchange 2003/2007 server I'll gladly adopt it. :)


I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Strongm, you got skills.

Working fine here on exch2003 for html mail, but text dosen't work for my edited one?

<SCRIPT LANGUAGE="VBScript">
Sub ISMTPOnArrival_OnArrival(ByVal Msg, EventStatus)
TextDisclaimer = vbCrLf & "DISCLAIMER:" & vbCrLf & "The content of this email and any attachments are CONFIDENTIAL and may contain privileged information. If you are not the addressee it may be UNLAWFUL for you to read, copy, distribute, disclose or otherwise use the information contained herein. The content of the message and or attachments may not reflect the view and opinions of the originating company or any party it is representing." & vbCrLf & "If you are NOT the intended recipient then please email back to ithelpdesk@testdomain.cdom"
HTMLDisclaimer = "<p></p><p>DISCLAIMER:<br>The content of this email and any attachments are CONFIDENTIAL and may contain privileged information. If you are not the addressee it may be UNLAWFUL for you to read, copy, distribute, disclose or otherwise use the information contained herein. The content of the message and or attachments may not reflect the view and opinions of the originating company or any party it is representing." & vbCrLf & "If you are NOT the intended recipient then please email back to ithelpdesk@testdomain.com"


If Msg.HTMLBody <> "" and Instr(Msg.HTMLBody,"The content of this email and any attachments are CONFIDENTIAL and may contain privileged information. If you are not the addressee it may be UNLAWFUL for you to read, copy, distribute, disclose or otherwise use the information contained herein. The content of the message and or attachments may not reflect the view and opinions of the originating company or any party it is representing." & vbCrLf & "If you are NOT the intended recipient then please email back to ithelpdesk@testdomain.com")=0 Then
'Search for the "</body>" tag and insert our disclaimer before that tag.
pos = InStr(1, Msg.HTMLBody, "</body>", vbTextCompare)
szPartI = Left(Msg.HTMLBody, pos - 1)
szPartII = Right(Msg.HTMLBody, Len(Msg.HTMLBody) - (pos - 1))
Msg.HTMLBody = szPartI + HTMLDisclaimer + szPartII
End If

If fred <> "" and Instr(fred,"The content of this email and any attachments are CONFIDENTIAL and may contain privileged information. If you are not the addressee it may be UNLAWFUL for you to read, copy, distribute, disclose or otherwise use the information contained herein. The content of the message and or attachments may not reflect the view and opinions of the originating company or any party it is representing." & vbCrLf & "If you are NOT the intended recipient then please email back to ithelpdesk@testdomain")=0 Then
Msg.TextBody = fred & vbCrLf & TextDisclaimer & vbCrLf
End If

'Commit the content changes to the transport ADO Stream object.
Msg.DataSource.Save ' Commit the changes into the transport Stream

EventStatus = 0 'cdoRunNextSink
End Sub
</SCRIPT>

Any ideas.
 
Bah! I copied and pasted too hurriedly from my test setup. In my script I didn't patch back the normal body text section to it's rightful state (I had introduced an extra variable to check the data going through and didn't clean it up properly when putting the sctipt back to normal)

Script should have read:
Code:
[blue]<SCRIPT LANGUAGE="VBScript">
Sub ISMTPOnArrival_OnArrival(ByVal Msg, EventStatus)
   TextDisclaimer = vbCrLf & "DISCLAIMER:" & vbCrLf & "Sample Disclaimer added in a VBScript."
   HTMLDisclaimer = "<p></p><p>DISCLAIMER:<br>Sample Disclaimer added in a VBScript."


   If Msg.HTMLBody <> ""  and Instr(Msg.HTMLBody,"Sample Disclaimer added in a VBScript.")=0 Then
      'Search for the "</body>" tag and insert our disclaimer before that tag.
      pos = InStr(1, Msg.HTMLBody, "</body>", vbTextCompare)
      szPartI = Left(Msg.HTMLBody, pos - 1)
      szPartII = Right(Msg.HTMLBody, Len(Msg.HTMLBody) - (pos - 1))
      Msg.HTMLBody = szPartI + HTMLDisclaimer + szPartII
   End If

   [b]If Msg.TextBody<> "" and Instr(Msg.TextBody,"Sample Disclaimer added in a VBScript.")=0 Then
      Msg.TextBody = Msg.TextBody & vbCrLf & TextDisclaimer & vbCrLf[/b]
   End If
    
   'Commit the content changes to the transport ADO Stream object.
   Msg.DataSource.Save ' Commit the changes into the transport Stream

   EventStatus =  0 'cdoRunNextSink
End Sub
</SCRIPT>[/blue]
 
A star from me Strongm. Nice work!

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Strongm, working like a charm here for html & txt.

Great work, owe you a beer!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top