Re: SMTP Protocol Event Sink to prevent mail from being sent

From: Victor Ivanidze (no_at_spam.please)
Date: 12/15/04


Date: Wed, 15 Dec 2004 16:38:14 +0300

Try to use another event:

STDMETHODIMP CSink::OnMessagePostCategorize(
        IMailMsgProperties *pMailMsg,
        IMailTransportNotify *pINotify,
        PVOID pvNotifyContext)

-- 
Regards,
Victor Ivanidze,
software developer
www.ivasoft.biz
"Chris Rose" <ChrisRose@discussions.microsoft.com> wrote in message
news:E1E7F3F1-0769-46E5-8456-C3A86B2458B0@microsoft.com...
> Hye,
>
> As a simple proof of concept I want to delete any outbound mail that is
sent
> from either Outlook or SMTP client if the subject does not contain the
word
> "Agreed".
>
> The following (VB COM DLL) Transport Event Sink works fine, so long as I
> install it on a second Virtual SMTP server so that Outlook mail is relayed
to
> it in SMTP format.
>
>
> Implements CDO.ISMTPOnArrival
>
> Private Sub ISMTPOnArrival_OnArrival(ByVal Msg As CDO.Message, EventStatus
> As CDO.CdoEventStatus)
>
>     Dim flds As ADODB.Fields
>
>     Set flds = Msg.EnvelopeFields
>
>     If Not InStr(Msg.Subject, "Agreed") > 0 Then
>
>
> flds("http://schemas.microsoft.com/cdo/smtpenvelope/messagestatus").Value
=
> cdoStatAbortDelivery
>         flds.Update
>
>         Msg.DataSource.Save
>
>         sSender = Msg.From
>
>         Dim oRejectionMessage As CDO.Message
>          Set oRejectionMessage = CreateObject("CDO.Message")
>          oRejectionMessage.To = sSender
>          oRejectionMessage.From = "MAILconsent"
>          oRejectionMessage.Subject = "Acceptable MAIL Usage Policy"
>          oRejectionMessage.TextBody = "Please read and agree to the policy
> first."
>          oRejectionMessage.Send
>          Set oRejectionMessage = Nothing  'release the object reference
>
>     End If
>
> End Sub
>
>
> I don't really want to have a second SMTP server, so I decided to look
into
> Protocol Events instead as I learnt that GFI adds disclaimers in this way.
I
> implemented this in C#. The event fires for both Outlook and SMTP clients
> which is exactly what I want, however I am unable to delete the message.
Both
> the AbortDelivery or BadMail message status' are ignored and the mail is
> delivered.
>
> If I change the Recipients List to a known different recipient the mail is
> delivered to the changed recipient so I know that I am kind of on the
right
> tracks. If I clear the list of recipients the mail is queued indefinitely
and
> seems to hold up all other mail.
>
> Here is the C# code:
>
> // registered for OnMessageStart event with the rule "mail from=*"
> [Guid("679CD792-463D-4c9f-B47B-D997A67B97C4")]
> public class SampleOutboundSink : ISmtpOutCommandSink
> {
>         void ISmtpOutCommandSink.OnSmtpOutCommand(
>                 object server,
>                 object session,
>                 MailMsg message,
>                 ISmtpOutCommandContext context)
>         {
>                 MailMsgPropertyBag Sever = new MailMsgPropertyBag(server);
>                 MailMsgPropertyBag Session = new
MailMsgPropertyBag(session);
>                 Message Msg = new Message(message);
>                 SmtpOutCommandContext Context = new
> SmtpOutCommandContext(context);
>
>                 String strMessage;
>                 if (Msg.Rfc822MsgSubject != null)
>                         strMessage = Msg.Rfc822MsgSubject.ToString();
>                 else
>                         strMessage = "";
>
>                 // if not Agreed then do not send mail
>                 if (strMessage.IndexOf("Agreed") == -1) {
>                         // create a blank list of recipients to stop this
> mail from being
>                         // delivered
>                         //RecipsAdd newRecips = Msg.AllocNewList();
>                         //newRecips.AddSMTPRecipient("");
>                         //Msg.WriteList(newRecips);
>
>                         Msg.MessageStatus =
> Message.MessageStatusEnum.BadMail;
>                         Msg.Commit();
>                 }
>
>                 Context.CommandStatus = (uint)
ProtocolEventConstants.S_OK;
>
>         }
> }
>
>
> Any help on this would be greatly appreciated. And I apologise for posting
a
> similar message earlier in the Exchange 2000 Development forum.
>
> Regards,
>
> Chris.
>


Relevant Pages

  • Re: filter recipients who are not in the directory questions
    ... Yes I enabled recipient filtering on my smtp virtual server. ... that they have a relay in front of exchange. ... Valid recipients include all mail-enabled objects - users, ...
    (microsoft.public.exchange.admin)
  • Re: Need some help with spam / Virus
    ... Was there another area that I needed to check under SMTP for this to work ... emails that do not exist on my AD? ... Your message did not reach some or all of the intended recipients. ... This is an automatically generated Delivery Status Notification. ...
    (microsoft.public.exchange.admin)
  • Re: 452 Error: too many recipients
    ... Mike on the south coast of the UK ... knock (on the SMTP provider's door) ... Send me the data or additional recipients ...
    (microsoft.public.outlook)
  • Re: Error 450 - too many recipient
    ... The only information I have is the response on the connection to smtp service: ... > As I outlined in my prev post, taking less than 100 recipients per message ... The general principle that relaying SMTP servers ... > But I've never seen exchange behaving like you described. ...
    (microsoft.public.exchange.applications)
  • Re: Error 450 - too many recipient
    ... The only information I have is the response on the connection to smtp service: ... > As I outlined in my prev post, taking less than 100 recipients per message ... The general principle that relaying SMTP servers ... > But I've never seen exchange behaving like you described. ...
    (microsoft.public.exchange2000.protocols)

Loading