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

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

  • Next message: Chris Rose: "Re: SMTP Protocol Event Sink to prevent mail from being sent"
    Date: Thu, 16 Dec 2004 09:10:57 +0300
    
    

    Chris,

    OnMessagePostCategorize event is fired on my Exchange 2000 server machine
    when message is sent from Outlook to external Internet recipient.

    -- 
    Thanks and regards,
    Victor Ivanidze,
    software developer
    www.ivasoft.biz
    > Victor,
    >
    > Thanks but OnMessagePostCategorize is a Transport Event in the same family
    > as OnMessageSubmission and these don't appear to be firing on my exchange
    > 2000 server when mail is sent from Outlook (please let me know if you have
    > experienced different behaviour). Transport events do fire when I use
    telnet.
    >
    > The Protocol Events such as OnMessageStart do get fired for Outlook mail,
    so
    > I need to somehow delete the message using one of these protocol events.
    >
    > Regards,
    >
    > Chris.
    >
    > "Victor Ivanidze" wrote:
    >
    > > 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.
    > > >
    > >
    > >
    > >
    

  • Next message: Chris Rose: "Re: SMTP Protocol Event Sink to prevent mail from being sent"

    Relevant Pages

    • RE: Can I restrict email sent in Outlook without using Exchange?
      ... that there is only one recipient. ... Dim cf As MAPIFolder ... We have 10 or so computers, each with a stand alone version of Outlook v.2000 ... PowerPoint) yet cannot seem to wrap my mind around how to accomplish this in ...
      (microsoft.public.outlook.program_vba)
    • Re: why cant i send doc by email
      ... Recipient using Internet fax service ... Outlook Express, I can mail the open office document. ... On the the other three computers, I can e-mail and open office ...
      (microsoft.public.word.newusers)
    • Re: Error handling for missing Outlook attachments
      ... When the directory path and/or file name for one or more attachments is ... Outlook Mailbox, and send the problem email to this, instead of sending the ... Dim oApp As Outlook.Application ... oMailItem.Recipients.Add Cells'Identify Email Recipient ...
      (microsoft.public.excel.programming)
    • Re: Load a recipient based on a value in a combo box
      ... display names in the recipient field when selected. ... get it to work like Outlook 2003. ... Set Recipient = Recipients.Add ... And I suspect it's bound to a custom ...
      (microsoft.public.outlook.program_forms)
    • Re: custom SMS gateway
      ... Author of Microsoft Outlook 2007 Programming: ... Dim oDialog As SelectNamesDialog ... Dim Recp As Recipient ...
      (microsoft.public.outlook.program_vba)

    Loading