//static void s_ConfigurationChangeWatcher_Changed(object sender, FileSystemEventArgs e) //{ // Configure(e.FullPath); //} void IMailTransportSubmission.OnMessageSubmission( MailMsg mailmsg, IMailTransportNotify notify, IntPtr context) { LogDebug("Invoking mail sink message submission callback."); try { Message message = new Message(mailmsg); LogDebug(string.Format("Processing message \"{0}\" ({1} byte(s)).", message.Rfc822MsgSubject, message.GetContentSize())); byte[] content = message.ReadContent(0, message.GetContentSize()); string filename = s_QueuePath + "\\" + message.Rfc822MsgId; filename = filename.Replace("<", "_").Replace(">", "_").Replace(" ", "_"); LogDebug(string.Format("Dumping message \"{0}\" to {1}.", message.Rfc822MsgSubject, filename)); File.WriteAllBytes(filename, content); } catch (Exception ex) { LogError(ex.Message + "\n" + ex.StackTrace.ToString()); } finally { if (null != mailmsg) { Marshal.ReleaseComObject(mailmsg); } } }
void IMailTransportSubmission.OnMessageSubmission( MailMsg message, IMailTransportNotify notify, IntPtr context) { try { Message Msg = new Message(message); if (Debug) { EventLog.WriteEntry( Assembly.GetExecutingAssembly().FullName, "Checking message " + Msg.Rfc822MsgId + " with subject \"" + Msg.Rfc822MsgSubject + "\".", EventLogEntryType.Information); } RecipsAdd NewRecipients = Msg.AllocNewList(); bool fReRouted = false; foreach (Recip Recipient in Msg.Recips) { try { fReRouted |= ReRoute(Recipient, Msg, NewRecipients); } catch (Exception ex) { EventLog.WriteEntry( Assembly.GetExecutingAssembly().FullName, "Error routing message " + Msg.Rfc822MsgId + " to " + Recipient.SMTPAddress + "." + ex.Message, EventLogEntryType.Error); } } if (fReRouted) { Msg.WriteList(NewRecipients); } } catch (Exception ex) { EventLog.WriteEntry( Assembly.GetExecutingAssembly().FullName, ex.Message + "\n" + ex.StackTrace.ToString(), EventLogEntryType.Error); } finally { if (null != message) Marshal.ReleaseComObject(message); } }