public MailMessage CreateMailMessage(Email email)
        {
            var rawEmailString = _emailViewRenderer.Render(email);
            var mailMessage    = _emailParser.Parse(rawEmailString, email);

            return(mailMessage);
        }
Example #2
0
        /// <summary>
        /// Renders the email view and builds a <see cref="MailMessage"/>. Does not send the email.
        /// </summary>
        /// <param name="email">The email to render.</param>
        /// <returns>A <see cref="MailMessage"/> containing the rendered email.</returns>
        public MailMessage CreateMailMessage(Email email)
        {
#if ASPNET5
            var rawEmailString = emailViewRenderer.Render(email, RequestUrl);
            emailParser = new EmailParser(emailViewRenderer, RequestUrl);
#else
            var rawEmailString = emailViewRenderer.Render(email, request: Request);
#endif
            var mailMessage = emailParser.Parse(rawEmailString, email);
            return(mailMessage);
        }
Example #3
0
        public void ReadEmlTest()
        {
            string        path    = TestDataSample.GetEmailPath("test.eml");
            ParserContext context = new ParserContext(path);
            IEmailParser  parser  = ParserFactory.CreateEmail(context);
            ToxyEmail     email   = parser.Parse();

            Assert.IsNotNullOrEmpty(email.From);
            Assert.AreEqual(1, email.To.Count);
            Assert.AreEqual("=?utf-8?B?5ouJ5Yu+572R?= <*****@*****.**>", email.From);
            Assert.AreEqual("*****@*****.**", email.To[0]);

            Assert.IsTrue(email.Subject.StartsWith("=?utf-8?B?5LiK5rW35YiG5LyX5b635bOw5bm/5ZGK?= =?utf-8?B?5Lyg5p"));
            Assert.IsTrue(email.TextBody.StartsWith("------=_Part_4546_1557510524.1418357602217\r\nContent-Type: text"));
            Assert.IsNull(email.HtmlBody);
        }
Example #4
0
        public void ReadCnmTest()
        {
            string        path    = TestDataSample.GetCNMPath("Y0B6E8H2.CNM");
            ParserContext context = new ParserContext(path);
            IEmailParser  parser  = ParserFactory.CreateEmail(context) as IEmailParser;
            ToxyEmail     email   = parser.Parse();

            Assert.AreEqual(1, email.From.Count);
            Assert.AreEqual(1, email.To.Count);
            Assert.AreEqual("Тюльпаны <*****@*****.**>", email.From[0]);
            Assert.AreEqual("<*****@*****.**>", email.To[0]);

            Assert.AreEqual("Тюльпаны", email.Subject);
            Assert.IsTrue(email.Body.StartsWith("Тел: 960-51-57;Продажа тюльпанов"));
            Assert.IsTrue(email.HtmlBody.StartsWith("<!DOCTYPE HTML"));
        }
Example #5
0
        public void ReadEmlTest()
        {
            string        path    = TestDataSample.GetEmailPath("test.eml");
            ParserContext context = new ParserContext(path);
            IEmailParser  parser  = ParserFactory.CreateEmail(context);
            ToxyEmail     email   = parser.Parse();

            Assert.IsNotNull(email.From);
            Assert.IsNotEmpty(email.From);
            Assert.AreEqual(1, email.To.Count);
            Assert.AreEqual(email.From, "\u62C9\u52FE\u7F51 <*****@*****.**>");
            Assert.AreEqual(email.To[0], "*****@*****.**");

            Assert.AreEqual(email.Subject, "\u4E0A\u6D77\u5206\u4F17\u5FB7\u5CF0\u5E7F\u544A\u4F20\u64AD\u6709\u9650\u516C\u53F8-\u9AD8\u7EA7.NET\u8F6F\u4EF6\u5DE5\u7A0B\u5E08\u62DB\u8058\u53CD\u9988\u901A\u77E5");
            Assert.IsTrue(email.HtmlBody.StartsWith("<html>\r\n"));
            Assert.IsNull(email.TextBody);
        }
        public IEnumerable <OutageMailMessage> GetUnreadMessages()
        {
            if (!_client.IsConnected)
            {
                throw new NullReferenceException("ImapClient is a null value (not connected).");
            }

            Message[] messages = _client.Folders["INBOX"].Search("UNSEEN", MessageFetchMode.Full);

            List <OutageMailMessage> outageMailMessages = new List <OutageMailMessage>();

            foreach (Message message in messages)
            {
                OutageMailMessage outageMessage = _mapper.MapMail(message);
                outageMailMessages.Add(outageMessage);
                message.Seen = true;

                OutageTracingModel tracingModel = _parser.Parse(outageMessage);

                if (tracingModel.IsValidReport)
                {
                    _dispatcher.Dispatch(tracingModel.Gid);
                }

                try
                {
                    _publisher.Publish(
                        publication: new OutageEmailPublication(Topic.OUTAGE_EMAIL, new EmailToOutageMessage(tracingModel.Gid)),
                        publisherName: "Email Service"
                        );
                }
                catch (Exception)
                {
                    Console.WriteLine("[ImapEmailClient::GetUnreadMessages] Sending to PubSub Engine failed.");
                }
            }

            return(outageMailMessages);
        }
        public IEnumerable <OutageMailMessage> GetUnreadMessages()
        {
            var outageMailMessages = new List <OutageMailMessage>();

            try
            {
                if (!client.IsConnected)
                {
                    if (!client.Connect())
                    {
                        Logger.LogError($"{baseLogString} GetUnreadMessages => client could not connect to the email server.");
                        return(outageMailMessages);
                    }
                }

                Message[] messages = client.Folders["INBOX"].Search("UNSEEN", MessageFetchMode.Full);

                foreach (Message message in messages)
                {
                    OutageMailMessage outageMessage = mapper.MapMail(message);

                    outageMailMessages.Add(outageMessage);
                    message.Seen = true;

                    OutageTracingModel tracingModel = parser.Parse(outageMessage);

                    publisher.Publish(new OutageEmailPublication(Topic.OUTAGE_EMAIL, new EmailToOutageMessage(tracingModel.Gid)), MicroserviceNames.OmsEmailService).Wait();
                }
            }
            catch (Exception e)
            {
                Logger.LogError($"{baseLogString} GetUnreadMessages => Message: {e.Message}", e);
            }

            return(outageMailMessages);
        }