Ejemplo n.º 1
0
        void SendMessage(IMessage msg, String receiver, String seqNum)
        {
            if (msg == null)
            {
                throw new ArgumentNullException("msg");
            }

            InternalRemotingServices.RemotingTrace("SmtpMessageSink::ProcessAndSend 1");

            //
            // Serialize the message
            //
            byte [] byteMessage;
            int     byteMessageLength = 0;

            InternalRemotingServices.RemotingTrace("SmtpMessageSink::ProcessAndSend 2");

            MemoryStream stm = (MemoryStream)CoreChannel.SerializeMessage(m_mimeType, msg);

            InternalRemotingServices.RemotingTrace("SmtpMessageSink::ProcessAndSend 3");
            // reset stream to beginning
            stm.Position      = 0;
            byteMessage       = stm.ToArray();
            byteMessageLength = byteMessage.Length;

            //
            // Create a new mail message
            //
            MailMessage mail = new MailMessage();

            // Add the required and optional headers
            PutHeaders(mail, (IMethodCallMessage)msg, receiver, seqNum, byteMessageLength);

            // Add the body of the message
            mail.Body = System.Text.Encoding.ASCII.GetString(byteMessage, 0, byteMessage.Length);

            //
            // Send request
            //
            InternalRemotingServices.RemotingTrace("SmtpMessageSink::ProcessAndSend before Send");
            SmtpMail.Send(mail);
        }
Ejemplo n.º 2
0
        // Generates a reply to an incoming Smtp message and sends it
        void ReplyMessage(IMessage replyMsg, ISmtpMessage smtpInMsg,
                          String seqNum, Smtp.Fields headers)
        {
            MemoryStream stm = (MemoryStream)CoreChannel.SerializeMessage(m_mimeType, replyMsg);

            // reset stream to beginning
            stm.Position = 0;
            byte[] byteMessage       = stm.ToArray();
            int    byteMessageLength = byteMessage.Length;
            String reply             = System.Text.Encoding.ASCII.GetString(byteMessage, 0, byteMessage.Length);

            // Create a reply message
            MailMessage smtpOutMsg = new MailMessage();

            // Fill in the headers
            PutHeaders(smtpOutMsg, smtpInMsg, (IMethodMessage)replyMsg, seqNum, reply.Length);

            // Set the body
            smtpOutMsg.Body = reply;

            // Send the message
            SmtpMail.Send(smtpOutMsg);
        }