| Author |
Message |
Guest
|
Posted:
Thu Aug 04, 2005 4:59 pm Post subject:
SMTP OnArrival Transport Event Sink |
|
|
Hi,
I'm trying to implement a transport event sink to respond to messages sent
to a particular external e-mail address (let's say name@example.com). I
register the sink with the rule "rcpt to=name@example.com" and found out
that the sink is invoked if I send a message directly to name@example.com,
but is not invoked if I send it to a Contact created in Active Directory
(even if the message is delivered correctly). I guess this happens because
the sink rule is checked before the contact is resolved in its SMTP address.
Infact, looking at the SMTP log, I see that the recipient address is in the
AD LDAP format in the first entries and in SMTP format only on latest
entries.
Is there any way to intercept both the events ?
Thanks.
Massimo.
|
|
| Back to top |
|
 |
Joe
Guest
|
Posted:
Fri Aug 05, 2005 12:59 am Post subject:
RE: SMTP OnArrival Transport Event Sink |
|
|
If you don't mind me asking could you post your code. I am trying to write
an event sink which would automatically reply after an e-mail is sent to an
address, but I have not been successful. Thanks.
"m.piceni@newsgroup.nospam" wrote:
| Quote: | Hi,
I'm trying to implement a transport event sink to respond to messages sent
to a particular external e-mail address (let's say name@example.com). I
register the sink with the rule "rcpt to=name@example.com" and found out
that the sink is invoked if I send a message directly to name@example.com,
but is not invoked if I send it to a Contact created in Active Directory
(even if the message is delivered correctly). I guess this happens because
the sink rule is checked before the contact is resolved in its SMTP address.
Infact, looking at the SMTP log, I see that the recipient address is in the
AD LDAP format in the first entries and in SMTP format only on latest
entries.
Is there any way to intercept both the events ?
Thanks.
Massimo.
|
|
|
| Back to top |
|
 |
Guest
|
Posted:
Fri Aug 05, 2005 8:58 am Post subject:
Re: SMTP OnArrival Transport Event Sink |
|
|
Hi Joe,
at the moment I'm just making some testing with a very simple VBS script
that logs the messages and deletes them. Here it is, but it's not so clever
and not commented at all (don't try it in your production environment!!!):
<SCRIPT LANGUAGE="VBScript">
Const cdoRunNextSink = 0
Const cdoSkipRemainingSinks = 1
Const cdoStatAbortDelivery = 2
Const cdoStatBadMail = 3
Sub ISMTPOnArrival_OnArrival(ByVal Msg, EventStatus )
Dim fs
Set fs = CreateObject("Scripting.FileSystemObject")
Dim file
Set file = fs.OpenTextFile("E:\exchserv\EventSink\sinktest.txt", 8, True )
file.Write "From: " & Msg.From & vbCrLf
file.Write "To: " & Msg.To & vbCrLf
file.Write "Subject: " & Msg.Subject & vbCrLf & vbCrLf
file.Write Msg.TextBody & vbCrLf & vbCrLf
file.Close
Msg.EnvelopeFields.Item("http://schemas.microsoft.com/cdo/smtpenvelope/messa
gestatus").Value = cdoStatAbortDelivery
Msg.EnvelopeFields.Update
EventStatus = cdoSkipRemainingSinks
End Sub
</SCRIPT>
To register it, you can do something like this (you'll need the smtpreg.vbs
from Exchange SDK):
cscript smtpreg.vbs /add 1 onarrival SinkTest CDO.SS_SMTPOnArrivalSink
"rcpt to=*@example.com"
cscript smtpreg.vbs /setprop 1 onarrival SinkTest Sink ScriptName
"e:\exchserv\EventSink\logsink.vbs"
You may need to change path and name of the script and the rule. I use
*@example.com for testing because example.com is a domain that doesn't
exists (if I make mistakes, I'm sure not to spam anyone!!!).
To unregister:
cscript smtpreg.vbs /remove 1 onarrival SinkTest
If you like VBS for making transport event sinks, take a look at this:
http://playground.doesntexist.org/
At the bottom of Download page there's an interesting collection of
Transport Event Sink scripts.
Enjoy.
Massimo.
"Joe" <Joe@discussions.microsoft.com> ha scritto nel messaggio
news:8740149C-0BF0-4F4E-B840-9014DA936A0A@microsoft.com...
| Quote: | If you don't mind me asking could you post your code. I am trying to
write
an event sink which would automatically reply after an e-mail is sent to
an
address, but I have not been successful. Thanks.
"m.piceni@newsgroup.nospam" wrote:
Hi,
I'm trying to implement a transport event sink to respond to messages
sent
to a particular external e-mail address (let's say name@example.com). I
register the sink with the rule "rcpt to=name@example.com" and found out
that the sink is invoked if I send a message directly to
name@example.com,
but is not invoked if I send it to a Contact created in Active Directory
(even if the message is delivered correctly). I guess this happens
because
the sink rule is checked before the contact is resolved in its SMTP
address.
Infact, looking at the SMTP log, I see that the recipient address is in
the
AD LDAP format in the first entries and in SMTP format only on latest
entries.
Is there any way to intercept both the events ?
Thanks.
Massimo.
|
|
|
| Back to top |
|
 |
Guest
|
Posted:
Fri Aug 05, 2005 2:19 pm Post subject:
Re: SMTP OnArrival Transport Event Sink |
|
|
Going further, I find out that even using the rule "rcpt to=*" the messages
sent to the AD Contact are not passed to the sink, even if they're going out
of the exchange organizzation. This is quite amazing.
Any idea ?
Massimo.
<m.piceni@newsgroup.nospam> ha scritto nel messaggio
news:%237btg2QmFHA.1372@TK2MSFTNGP10.phx.gbl...
| Quote: | Hi,
I'm trying to implement a transport event sink to respond to messages sent
to a particular external e-mail address (let's say name@example.com). I
register the sink with the rule "rcpt to=name@example.com" and found out
that the sink is invoked if I send a message directly to name@example.com,
but is not invoked if I send it to a Contact created in Active Directory
(even if the message is delivered correctly). I guess this happens because
the sink rule is checked before the contact is resolved in its SMTP
address.
Infact, looking at the SMTP log, I see that the recipient address is in
the
AD LDAP format in the first entries and in SMTP format only on latest
entries.
Is there any way to intercept both the events ?
Thanks.
Massimo.
|
|
|
| Back to top |
|
 |
joe
Guest
|
Posted:
Sat Aug 06, 2005 12:59 am Post subject:
Re: SMTP OnArrival Transport Event Sink |
|
|
Thank you for sharing your code. I really appreciate that.
You see in my Exchange 2003 environment automatic replies to the internet
is disabled, but I have two mailboxes in the environment for which I need to
enable automatic replies to the internet. I heard that I would have to write
an exchange
event sink, and that is when I decided to investigate writing event sink.
I am going to try to do a recipient filter, and if the mail is going to those
two mailboxes, I want the exchange server to automatically reply with a
specific message to the sender of the message. Having the server reply is
the part that I am having a hard time with. I spent six hours last night
trying to figure it out, and still I could not pull it off. My code is
listed below. Thanks.
<SCRIPT LANGUAGE="VBScript">
Set objEmail = CreateObject("CDO.Message")
Sub IEventIsCacheable_IsCacheable()
'To implement the interface, and return S_OK implicitly
End Sub
Sub ISMTPOnArrival_OnArrival(ByVal Msg, EventStatus)
Dim envFlds
Dim iFound
Set envFlds = Msg.EnvelopeFields
'identifying the sender so an e-mail can be sent back
sender=msg.from
'condition to if the mail is going to the careers mailbox
If Msg.to= "careers@jmcc.com" Then
objEmail.From = "careers@jmcc.com"
objEmail.To = sender
objEmail.Subject = "Thank you"
objEmail.Textbody = "We have received your resume, and we will review it.
We will contact you."
objEmail.Send
End If
End Sub
</SCRIPT>
"m.piceni@newsgroup.nospam" wrote:
| Quote: | Hi Joe,
at the moment I'm just making some testing with a very simple VBS script
that logs the messages and deletes them. Here it is, but it's not so clever
and not commented at all (don't try it in your production environment!!!):
SCRIPT LANGUAGE="VBScript"
Const cdoRunNextSink = 0
Const cdoSkipRemainingSinks = 1
Const cdoStatAbortDelivery = 2
Const cdoStatBadMail = 3
Sub ISMTPOnArrival_OnArrival(ByVal Msg, EventStatus )
Dim fs
Set fs = CreateObject("Scripting.FileSystemObject")
Dim file
Set file = fs.OpenTextFile("E:\exchserv\EventSink\sinktest.txt", 8, True )
file.Write "From: " & Msg.From & vbCrLf
file.Write "To: " & Msg.To & vbCrLf
file.Write "Subject: " & Msg.Subject & vbCrLf & vbCrLf
file.Write Msg.TextBody & vbCrLf & vbCrLf
file.Close
Msg.EnvelopeFields.Item("http://schemas.microsoft.com/cdo/smtpenvelope/messa
gestatus").Value = cdoStatAbortDelivery
Msg.EnvelopeFields.Update
EventStatus = cdoSkipRemainingSinks
End Sub
/SCRIPT
To register it, you can do something like this (you'll need the smtpreg.vbs
from Exchange SDK):
cscript smtpreg.vbs /add 1 onarrival SinkTest CDO.SS_SMTPOnArrivalSink
"rcpt to=*@example.com"
cscript smtpreg.vbs /setprop 1 onarrival SinkTest Sink ScriptName
"e:\exchserv\EventSink\logsink.vbs"
You may need to change path and name of the script and the rule. I use
*@example.com for testing because example.com is a domain that doesn't
exists (if I make mistakes, I'm sure not to spam anyone!!!).
To unregister:
cscript smtpreg.vbs /remove 1 onarrival SinkTest
If you like VBS for making transport event sinks, take a look at this:
http://playground.doesntexist.org/
At the bottom of Download page there's an interesting collection of
Transport Event Sink scripts.
Enjoy.
Massimo.
"Joe" <Joe@discussions.microsoft.com> ha scritto nel messaggio
news:8740149C-0BF0-4F4E-B840-9014DA936A0A@microsoft.com...
If you don't mind me asking could you post your code. I am trying to
write
an event sink which would automatically reply after an e-mail is sent to
an
address, but I have not been successful. Thanks.
"m.piceni@newsgroup.nospam" wrote:
Hi,
I'm trying to implement a transport event sink to respond to messages
sent
to a particular external e-mail address (let's say name@example.com). I
register the sink with the rule "rcpt to=name@example.com" and found out
that the sink is invoked if I send a message directly to
name@example.com,
but is not invoked if I send it to a Contact created in Active Directory
(even if the message is delivered correctly). I guess this happens
because
the sink rule is checked before the contact is resolved in its SMTP
address.
Infact, looking at the SMTP log, I see that the recipient address is in
the
AD LDAP format in the first entries and in SMTP format only on latest
entries.
Is there any way to intercept both the events ?
Thanks.
Massimo.
|
|
|
| Back to top |
|
 |
Henning Krause [MVP - Exc
Guest
|
Posted:
Sun Aug 07, 2005 10:51 pm Post subject:
Re: SMTP OnArrival Transport Event Sink |
|
|
Hello Massimo,
you can force the address into SMTP form with a second virtual SMTP server.
Create a SMTP connector and let the smarthost point to your second virtual
Server, which in turn delivers mail via DNS resolution. Install your event
sink on the second virtual server.
See this KB article on that topic:
http://support.microsoft.com/default.aspx?scid=kb;en-us;273233
Greetings,
Henning Krause
MVP - Exchange
http://www.infinitec.de
<m.piceni@newsgroup.nospam> wrote in message
news:%237btg2QmFHA.1372@TK2MSFTNGP10.phx.gbl...
| Quote: | Hi,
I'm trying to implement a transport event sink to respond to messages sent
to a particular external e-mail address (let's say name@example.com). I
register the sink with the rule "rcpt to=name@example.com" and found out
that the sink is invoked if I send a message directly to name@example.com,
but is not invoked if I send it to a Contact created in Active Directory
(even if the message is delivered correctly). I guess this happens because
the sink rule is checked before the contact is resolved in its SMTP
address.
Infact, looking at the SMTP log, I see that the recipient address is in
the
AD LDAP format in the first entries and in SMTP format only on latest
entries.
Is there any way to intercept both the events ?
Thanks.
Massimo.
|
|
|
| Back to top |
|
 |
Guest
|
Posted:
Mon Aug 08, 2005 4:59 pm Post subject:
Re: SMTP OnArrival Transport Event Sink |
|
|
Hi Joe,
have you tryed to create the objEmail like this:
Set objEmail = Msg.Reply
instead of creating it from scratch via CDO as you did in your code ? I made
some testing replying in this way and works fine.
By the way, to achieve your purpose you may also create a Server-side rule
on your mailbox(es). You can simply use Outlook to do this. A Server-side
rule doesn't need Outlook to function, you just need Outlook to create (or
modify) the rules.
Massimo.
"joe" <joe@discussions.microsoft.com> ha scritto nel messaggio
news:43D5E0F3-E514-4758-8EC9-67131E3F0315@microsoft.com...
| Quote: | Thank you for sharing your code. I really appreciate that.
You see in my Exchange 2003 environment automatic replies to the internet
is disabled, but I have two mailboxes in the environment for which I need
to
enable automatic replies to the internet. I heard that I would have to
write
an exchange
event sink, and that is when I decided to investigate writing event sink.
I am going to try to do a recipient filter, and if the mail is going to
those
two mailboxes, I want the exchange server to automatically reply with a
specific message to the sender of the message. Having the server reply
is
the part that I am having a hard time with. I spent six hours last night
trying to figure it out, and still I could not pull it off. My code is
listed below. Thanks.
SCRIPT LANGUAGE="VBScript"
Set objEmail = CreateObject("CDO.Message")
Sub IEventIsCacheable_IsCacheable()
'To implement the interface, and return S_OK implicitly
End Sub
Sub ISMTPOnArrival_OnArrival(ByVal Msg, EventStatus)
Dim envFlds
Dim iFound
Set envFlds = Msg.EnvelopeFields
'identifying the sender so an e-mail can be sent back
sender=msg.from
'condition to if the mail is going to the careers mailbox
If Msg.to= "careers@jmcc.com" Then
objEmail.From = "careers@jmcc.com"
objEmail.To = sender
objEmail.Subject = "Thank you"
objEmail.Textbody = "We have received your resume, and we will review it.
We will contact you."
objEmail.Send
End If
End Sub
/SCRIPT
"m.piceni@newsgroup.nospam" wrote:
Hi Joe,
at the moment I'm just making some testing with a very simple VBS script
that logs the messages and deletes them. Here it is, but it's not so
clever
and not commented at all (don't try it in your production
environment!!!):
SCRIPT LANGUAGE="VBScript"
Const cdoRunNextSink = 0
Const cdoSkipRemainingSinks = 1
Const cdoStatAbortDelivery = 2
Const cdoStatBadMail = 3
Sub ISMTPOnArrival_OnArrival(ByVal Msg, EventStatus )
Dim fs
Set fs = CreateObject("Scripting.FileSystemObject")
Dim file
Set file = fs.OpenTextFile("E:\exchserv\EventSink\sinktest.txt", 8,
True )
file.Write "From: " & Msg.From & vbCrLf
file.Write "To: " & Msg.To & vbCrLf
file.Write "Subject: " & Msg.Subject & vbCrLf & vbCrLf
file.Write Msg.TextBody & vbCrLf & vbCrLf
file.Close
Msg.EnvelopeFields.Item("http://schemas.microsoft.com/cdo/smtpenvelope/messa
gestatus").Value = cdoStatAbortDelivery
Msg.EnvelopeFields.Update
EventStatus = cdoSkipRemainingSinks
End Sub
/SCRIPT
To register it, you can do something like this (you'll need the
smtpreg.vbs
from Exchange SDK):
cscript smtpreg.vbs /add 1 onarrival SinkTest CDO.SS_SMTPOnArrivalSink
"rcpt to=*@example.com"
cscript smtpreg.vbs /setprop 1 onarrival SinkTest Sink ScriptName
"e:\exchserv\EventSink\logsink.vbs"
You may need to change path and name of the script and the rule. I use
*@example.com for testing because example.com is a domain that doesn't
exists (if I make mistakes, I'm sure not to spam anyone!!!).
To unregister:
cscript smtpreg.vbs /remove 1 onarrival SinkTest
If you like VBS for making transport event sinks, take a look at this:
http://playground.doesntexist.org/
At the bottom of Download page there's an interesting collection of
Transport Event Sink scripts.
Enjoy.
Massimo.
"Joe" <Joe@discussions.microsoft.com> ha scritto nel messaggio
news:8740149C-0BF0-4F4E-B840-9014DA936A0A@microsoft.com...
If you don't mind me asking could you post your code. I am trying to
write
an event sink which would automatically reply after an e-mail is sent
to
an
address, but I have not been successful. Thanks.
"m.piceni@newsgroup.nospam" wrote:
Hi,
I'm trying to implement a transport event sink to respond to
messages
sent
to a particular external e-mail address (let's say
name@example.com). I
register the sink with the rule "rcpt to=name@example.com" and found
out
that the sink is invoked if I send a message directly to
name@example.com,
but is not invoked if I send it to a Contact created in Active
Directory
(even if the message is delivered correctly). I guess this happens
because
the sink rule is checked before the contact is resolved in its SMTP
address.
Infact, looking at the SMTP log, I see that the recipient address is
in
the
AD LDAP format in the first entries and in SMTP format only on
latest
entries.
Is there any way to intercept both the events ?
Thanks.
Massimo.
|
|
|
| Back to top |
|
 |
joe
Guest
|
Posted:
Wed Aug 10, 2005 10:58 pm Post subject:
Re: SMTP OnArrival Transport Event Sink |
|
|
When I tried the msg.reply it didn't work. Instead what I ended up doing was
have the script extract the sender list, and the recipient list. Based on
the recipient list, I send back a message using the method of sending mails
through an smtp server. A copy of my code is listed below, and it works just
fine when it runs on a windows 2003 server with the smtp service enabled.
Exchange is not even needed. Thanks for all your help.
<SCRIPT LANGUAGE="VBSCRIPT">
'This script automatically replies to incoming mails being
'sent to a specific mailbox from outside since automatic replies to the
internet is disabled
'------------------------------------------------------------------------------
Const Reciplist="careers@domain.com"
Sub IEventIsCacheable_IsCacheable()
'To implement the interface, and return S_OK implicitly
End Sub
Sub ISMTPOnArrival_OnArrival(ByVal objMessage, EventStatus)
' Initialize error checking
On Error Resume Next
' Declare variables
Dim strSender ' As String
Dim StrRecipient ' As String
Dim objFields ' As ADODB.Fields
' Get fields collection of message
Set objFields = objMessage.EnvelopeFields
With objFields
' Check sender
strSender =
LCase(.Item("http://schemas.microsoft.com/cdo/smtpenvelope/senderemailaddress").Value)
strRecipient =
LCase(.Item("http://schemas.microsoft.com/cdo/smtpenvelope/recipientlist").Value)
If InStr(strRecipient, Reciplist) <> 0 Then
Set objEmail = CreateObject("CDO.Message")
objEmail.From = "careers@domain.com"
objEmail.To = strSender
objEmail.Subject = "Thank you"
objEmail.Textbody = "We have received your recent inquiry concerning
employment with company"
objEmail.Send
End If
End With
Set objFields = Nothing
End Sub
</SCRIPT>
"m.piceni@newsgroup.nospam" wrote:
| Quote: | Hi Joe,
have you tryed to create the objEmail like this:
Set objEmail = Msg.Reply
instead of creating it from scratch via CDO as you did in your code ? I made
some testing replying in this way and works fine.
By the way, to achieve your purpose you may also create a Server-side rule
on your mailbox(es). You can simply use Outlook to do this. A Server-side
rule doesn't need Outlook to function, you just need Outlook to create (or
modify) the rules.
Massimo.
"joe" <joe@discussions.microsoft.com> ha scritto nel messaggio
news:43D5E0F3-E514-4758-8EC9-67131E3F0315@microsoft.com...
Thank you for sharing your code. I really appreciate that.
You see in my Exchange 2003 environment automatic replies to the internet
is disabled, but I have two mailboxes in the environment for which I need
to
enable automatic replies to the internet. I heard that I would have to
write
an exchange
event sink, and that is when I decided to investigate writing event sink.
I am going to try to do a recipient filter, and if the mail is going to
those
two mailboxes, I want the exchange server to automatically reply with a
specific message to the sender of the message. Having the server reply
is
the part that I am having a hard time with. I spent six hours last night
trying to figure it out, and still I could not pull it off. My code is
listed below. Thanks.
SCRIPT LANGUAGE="VBScript"
Set objEmail = CreateObject("CDO.Message")
Sub IEventIsCacheable_IsCacheable()
'To implement the interface, and return S_OK implicitly
End Sub
Sub ISMTPOnArrival_OnArrival(ByVal Msg, EventStatus)
Dim envFlds
Dim iFound
Set envFlds = Msg.EnvelopeFields
'identifying the sender so an e-mail can be sent back
sender=msg.from
'condition to if the mail is going to the careers mailbox
If Msg.to= "careers@jmcc.com" Then
objEmail.From = "careers@jmcc.com"
objEmail.To = sender
objEmail.Subject = "Thank you"
objEmail.Textbody = "We have received your resume, and we will review it.
We will contact you."
objEmail.Send
End If
End Sub
/SCRIPT
"m.piceni@newsgroup.nospam" wrote:
Hi Joe,
at the moment I'm just making some testing with a very simple VBS script
that logs the messages and deletes them. Here it is, but it's not so
clever
and not commented at all (don't try it in your production
environment!!!):
SCRIPT LANGUAGE="VBScript"
Const cdoRunNextSink = 0
Const cdoSkipRemainingSinks = 1
Const cdoStatAbortDelivery = 2
Const cdoStatBadMail = 3
Sub ISMTPOnArrival_OnArrival(ByVal Msg, EventStatus )
Dim fs
Set fs = CreateObject("Scripting.FileSystemObject")
Dim file
Set file = fs.OpenTextFile("E:\exchserv\EventSink\sinktest.txt", 8,
True )
file.Write "From: " & Msg.From & vbCrLf
file.Write "To: " & Msg.To & vbCrLf
file.Write "Subject: " & Msg.Subject & vbCrLf & vbCrLf
file.Write Msg.TextBody & vbCrLf & vbCrLf
file.Close
Msg.EnvelopeFields.Item("http://schemas.microsoft.com/cdo/smtpenvelope/messa
gestatus").Value = cdoStatAbortDelivery
Msg.EnvelopeFields.Update
EventStatus = cdoSkipRemainingSinks
End Sub
/SCRIPT
To register it, you can do something like this (you'll need the
smtpreg.vbs
from Exchange SDK):
cscript smtpreg.vbs /add 1 onarrival SinkTest CDO.SS_SMTPOnArrivalSink
"rcpt to=*@example.com"
cscript smtpreg.vbs /setprop 1 onarrival SinkTest Sink ScriptName
"e:\exchserv\EventSink\logsink.vbs"
You may need to change path and name of the script and the rule. I use
*@example.com for testing because example.com is a domain that doesn't
exists (if I make mistakes, I'm sure not to spam anyone!!!).
To unregister:
cscript smtpreg.vbs /remove 1 onarrival SinkTest
If you like VBS for making transport event sinks, take a look at this:
http://playground.doesntexist.org/
At the bottom of Download page there's an interesting collection of
Transport Event Sink scripts.
Enjoy.
Massimo.
"Joe" <Joe@discussions.microsoft.com> ha scritto nel messaggio
news:8740149C-0BF0-4F4E-B840-9014DA936A0A@microsoft.com...
If you don't mind me asking could you post your code. I am trying to
write
an event sink which would automatically reply after an e-mail is sent
to
an
address, but I have not been successful. Thanks.
"m.piceni@newsgroup.nospam" wrote:
Hi,
I'm trying to implement a transport event sink to respond to
messages
sent
to a particular external e-mail address (let's say
name@example.com). I
register the sink with the rule "rcpt to=name@example.com" and found
out
that the sink is invoked if I send a message directly to
name@example.com,
but is not invoked if I send it to a Contact created in Active
Directory
(even if the message is delivered correctly). I guess this happens
because
the sink rule is checked before the contact is resolved in its SMTP
address.
Infact, looking at the SMTP log, I see that the recipient address is
in
the
AD LDAP format in the first entries and in SMTP format only on
latest
entries.
Is there any way to intercept both the events ?
Thanks.
Massimo.
|
|
|
| Back to top |
|
 |
|
|
|
|