Ejemplo n.º 1
0
        public void TestFailedDeliveryStatusSerialization()
        {
            Message source = this.CreateSourceMessage();

            DSN        dsnExpected = this.CreateFailedStatusNotification(3);
            DSNMessage dsnMessage  = source.CreateStatusMessage(new MailAddress(Postmaster), dsnExpected);

            Console.WriteLine(dsnMessage);
            var path = Path.GetTempFileName();

            try
            {
                dsnMessage.Save(path);
                Message loadedMessage = Message.Load(File.ReadAllText(path));
                Assert.True(loadedMessage.IsDSN());
                Assert.Equal(dsnMessage.ParsedContentType.MediaType, loadedMessage.ParsedContentType.MediaType);
                Assert.Equal(dsnMessage.SubjectValue, loadedMessage.SubjectValue);
                Assert.True(loadedMessage.HasHeader(MimeStandard.VersionHeader));
                Assert.True(loadedMessage.HasHeader(MailStandard.Headers.Date));
                Assert.True(loadedMessage.Headers.Count(x => (MimeStandard.Equals(x.Name, MimeStandard.VersionHeader))) == 1);
                var dsnActual = DSNParser.Parse(loadedMessage);

                VerifyEqual(dsnExpected, dsnActual);
            }
            finally
            {
                File.Delete(path);
            }
        }
Ejemplo n.º 2
0
        public void TestFailedDeliveryStatusNotification()
        {
            Message source = this.CreateSourceMessage();

            DSN        statusNotification = this.CreateFailedStatusNotification();
            DSNMessage dsnMessage         = source.CreateStatusMessage(new MailAddress(Postmaster), statusNotification);

            Assert.NotNull(dsnMessage);
            Console.WriteLine(dsnMessage);

            Assert.True(dsnMessage.IsDSN());
            Assert.True(dsnMessage.IsMultiPart);

            Assert.Equal(source.Headers.GetValue(MailStandard.Headers.From), dsnMessage.ToValue);
            Assert.Equal(Postmaster, dsnMessage.FromValue);

            Assert.Equal("Rejected:" + source.SubjectValue, dsnMessage.SubjectValue);

            Assert.True(dsnMessage.HasHeader(MimeStandard.VersionHeader));
            Assert.True(dsnMessage.HasHeader(MailStandard.Headers.Date));

            MimeEntity[] mdnEntities = dsnMessage.GetParts().ToArray();
            this.Verify(mdnEntities);

            this.VerifyDSNHeaders(mdnEntities[1], statusNotification);

            //Serialize and Deserialize
            Message message = MimeSerializer.Default.Deserialize <Message>(dsnMessage.ToString());

            Console.WriteLine(message);
        }
Ejemplo n.º 3
0
        private DSNMessage ReturnNoContextMessage(MimeMessage directMessage, string bodyMessage)
        {
            var to = new MailAddress(directMessage.From.Mailboxes.Single().ToString());

            var perMessage = new DSNPerMessage(
                to.Host,
                directMessage.MessageId);

            var dsnPerRecipients = new List <DSNPerRecipient>();

            foreach (var mailboxAddress in directMessage.To.Mailboxes)
            {
                var dsnPerRecipient = new DSNPerRecipient(
                    DSNStandard.DSNAction.Failed,
                    DSNStandard.DSNStatus.Permanent,
                    "3.3",
                    new MailAddress(mailboxAddress.ToString())
                    );

                dsnPerRecipients.Add(dsnPerRecipient);
            }

            var dsn = new DSN(perMessage, dsnPerRecipients);

            dsn.Explanation = bodyMessage;
            var postMaster = new MailAddress("Postmaster@" + to.Host);

            var statusMessage = new DSNMessage(to.Address, postMaster.Address, dsn);

            return(statusMessage);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// To simplify outbound mail sending, SMTP Server allows you to drop new messages into a pickup folder
        /// You don't need to use SmtpClient or some other SMTP client
        /// </summary>
        public void SendFailure(IncomingMessage envelope, string pickupFolder, DirectAddressCollection recipients)
        {
            if (string.IsNullOrEmpty(pickupFolder))
            {
                throw new ArgumentException("value null or empty", "pickupFolder");
            }

            if (recipients.IsNullOrEmpty())
            {
                return;
            }

            if (recipients != null)
            {
                DSNMessage notification = this.ProduceFailure(envelope, recipients);

                string filePath = Path.Combine(pickupFolder, Extensions.CreateUniqueFileName());
                notification.Save(filePath);
            }


            //Or maybe
            //
            // m_router.Route(message, envelope, routedRecipients);
            //
            // This would avoid loopback encrypt/decrypt...
            //
            // ISmtpMessage message
            // MessageEnvelope envelope
            // DirectAddressCollection routedRecipients, but would use DSN in-reply-to:
            //
        }
Ejemplo n.º 5
0
 private void DropMessage(DSNMessage dsnMessage)
 {
     using (Stream stream = File.OpenWrite(
                Path.Combine(
                    Settings.PickupFolder,
                    TestFilename)))
     {
         dsnMessage.Save(stream);
     }
 }
Ejemplo n.º 6
0
        public void TestNotificationOnNotication_FailedDeliveryStatus()
        {
            Message    source             = this.CreateSourceMessage();
            DSN        statusNotification = this.CreateFailedStatusNotification();
            DSNMessage dsnMessage         = source.CreateStatusMessage(new MailAddress(Postmaster), statusNotification);

            //
            // Shouldn never be able to issue a MDN for a DSN
            //
            Assert.Throws <DSNException>(() => dsnMessage.RequestNotification());
            Assert.Null(dsnMessage.CreateNotificationMessage(new MailAddress(Postmaster), statusNotification));
        }
Ejemplo n.º 7
0
        static DSNMessage CreateNotificationMessage(Mdn mdn, TimeoutSettings settings)
        {
            var perMessage   = new DSNPerMessage(settings.ProductName, mdn.MessageId);
            var perRecipient = new DSNPerRecipient(DSNStandard.DSNAction.Failed, DSNStandard.DSNStatus.Permanent
                                                   , DSNStandard.DSNStatus.NETWORK_EXPIRED_PROCESSED,
                                                   MailParser.ParseMailAddress(mdn.Recipient));
            //
            // The nature of Mdn storage in config store does not result in a list of perRecipients
            // If you would rather send one DSN with muliple recipients then one could write their own Job.
            //
            var notification = new DSN(perMessage, new List <DSNPerRecipient> {
                perRecipient
            });
            var sender = new MailAddress(mdn.Sender);
            var notificationMessage = new DSNMessage(sender.Address, new MailAddress("Postmaster@" + sender.Host).Address, notification);

            notificationMessage.AssignMessageID();
            notificationMessage.SubjectValue = string.Format("{0}:{1}", "Rejected", mdn.SubjectValue);
            notificationMessage.Timestamp();
            return(notificationMessage);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// To simplify inbound mail sending, SMTP Server allows you to drop new messages into a pickup folder
        /// You don't need to use SmtpClient or some other SMTP client
        /// </summary>
        public void SendFailure(OutgoingMessage envelope, string pickupFolder)
        {
            if (string.IsNullOrEmpty(pickupFolder))
            {
                throw new ArgumentException("value null or empty", "pickupFolder");
            }

            DirectAddressCollection recipients = envelope.RejectedRecipients;

            if (recipients.IsNullOrEmpty())
            {
                return;
            }

            if (recipients != null && envelope.UsingDeliveryStatus)
            {
                DSNMessage notification = this.ProduceFailure(envelope, recipients);


                string filePath = Path.Combine(pickupFolder, Extensions.CreateUniqueFileName());
                notification.Save(filePath);
            }
        }