private MailerMessage GetMailerMessage()
 {
     var mailerMessage = new MailerMessage();
     TryUpdateModel(mailerMessage);
     mailerMessage.Subject = string.Format("Adam.Kahtava.com response :: {0}", mailerMessage.Subject);
     mailerMessage.ToAddress = MyWebPresence.EmailAccount;
     mailerMessage.ToName = MyWebPresence.FullName;
     return mailerMessage;
 }
        public void ShouldVerify_HtmlStripperWithLinks()
        {
            var messageBody =
                new MailerMessage
                    {
                        Body = @"<blink>bling-bling</blink><br></p><hr><a href='http://www.google.com'>visit this link</a>&nbsp;<a href=""http://www.yahoo.com"">Or check out this link</a>"
                    }.Body;
            
            Console.WriteLine(messageBody);

            Assert.IsFalse(messageBody.Contains("blink"));
            Assert.IsFalse(messageBody.Contains("<br>"));
            Assert.IsTrue(messageBody.Contains("http://www.google.com"));
            Assert.IsTrue(messageBody.Contains("http://www.yahoo.com"));
        }
        public void ShouldVerify_HtmlStripperMoreComplexLinks()
        {
            string messageBody =
                new MailerMessage
                    {
                        Body =
                            @"<a href=""http://www.yahoo.com"">yahoo</a>, visit <a href=""http://www.bing.com"">bing</a>, visit <a href=""http://www.google.com"">google</a>, or check out <a href=""http://www.veer.com"">veer. also look into</a>"
                    }.Body;

            Console.WriteLine(messageBody);

            Assert.IsTrue(messageBody.Contains("http://www.yahoo.com"));
            Assert.IsTrue(messageBody.Contains("http://www.bing.com"));
            Assert.IsTrue(messageBody.Contains("http://www.google.com"));
            Assert.IsTrue(messageBody.Contains("http://www.veer.com"));
        }
Esempio n. 4
0
        public bool Send(MailerMessage mailerMessage)
        {
            try
            {
                var toAddress = new MailAddress(mailerMessage.ToAddress, mailerMessage.ToName);

                var fromAddress = new MailAddress(mailerMessage.FromAddress, mailerMessage.FromName);

                var mailMessage = new MailMessage(fromAddress, toAddress)
                                      {
                                          Subject = mailerMessage.Subject,
                                          Body = mailerMessage.Body
                                      };

                var client = new SmtpClient(smtpServerName)
                                 {
                                     UseDefaultCredentials = true,
                                     DeliveryMethod = SmtpDeliveryMethod.Network
                                 };

                client.Send(mailMessage);

                return true;
            }
            catch (SmtpException ex)
            {
                if(ex.StatusCode == SmtpStatusCode.TransactionFailed)
                {
                    if(ex.Message.ToLowerInvariant().Contains("spam"))
                    {
                        Errors.Add("content marked as spam");
                    }
                }
                return false;
            }
            catch
            {
                return false;
            }
        }
        public void ShouldVerify_HtmlStripperOnWeirdInput()
        {
            var messageBody = new MailerMessage { Body = @"-url- -url- <a href='dude'>hi</a> <a href='"" -url-</a> -url-" }.Body;

            Console.WriteLine(messageBody);
        }
        public void ShouldVerify_HtmlStripperOnHappyDays()
        {
            var messageBody = new MailerMessage { Body = @"hello" }.Body;

            Assert.IsTrue(messageBody.Contains("hello"));
        }
 public void ShouldVerify_ValidMessage()
 {
     var message = new MailerMessage { FromAddress = "*****@*****.**", Body = "valid-body" };
     Assert.IsTrue(message.IsValid());
 }
 public void ShouldVerify_InvalidEmailAddress()
 {
     var message = new MailerMessage {FromAddress = "invalidemailaddress", Body = "valid-body"};
     Assert.IsFalse(message.IsValid());
 }