상속: EmailMessage_Post
예제 #1
0
        public void send()
        {
            var emailMessage = new EmailMessage
                                    {
                                        To          = 10.randomLetters(),
                                        From        = 10.randomLetters(),
                                        Subject     = 10.randomLetters(),
                                        Message     = 10.randomLetters(),
                                        HtmlMessage = false
                                    };
            sendEmails.Smtp_Server   = 10.randomLetters();
            sendEmails.Smtp_UserName = 10.randomLetters();
            sendEmails.Smtp_Password = 10.randomLetters();

            //try with bad email values
            var result1 = sendEmails.send(emailMessage);
            Assert.IsFalse(sendEmails.serverNotConfigured());
            Assert.IsFalse(result1);
            Assert.AreEqual(emailMessage.SentStatus, SentStatus.Error);
            //try with good emails values
            SendEmails.Dont_Send_Emails = true;
            emailMessage.To   = "".random_Email();
            emailMessage.From = "from".random_Email();
            var result2 = sendEmails.send(emailMessage);
            Assert.IsTrue(result2);
            Assert.AreEqual(emailMessage.SentStatus, SentStatus.NotSent);
            SendEmails.Dont_Send_Emails = false;
        }
예제 #2
0
        public bool send(EmailMessage emailMessage)
        {
            if (emailMessage.isNull())
                return false;

            //emailMessage.Message += TMConsts.EMAIL_DEFAULT_FOOTER;
            emailMessage.Message += Email_Footer;
            Sent_EmailMessages.Add(emailMessage);

            if (emailMessage.From.notValid())
                emailMessage.From = this.From;
            TM_UserData.Current.logTBotActivity("Send Email","From: {0}    To: {1}    Subject: {2}".format(emailMessage.From, emailMessage.To, emailMessage.Subject));

            try
            {
                if (this.serverNotConfigured())
                {
                    emailMessage.SentStatus = SentStatus.NoConfig;
                    return false;
                }

                emailMessage.SentStatus = SentStatus.Sending;
                "Sending email:\n  to: {0}\n  from: {0}\n  subject: {0} ".info(emailMessage.To, emailMessage.Subject, emailMessage.Message);
                var mailMsg = new MailMessage();
                // To
                mailMsg.To.Add(new MailAddress(emailMessage.To));
                // From
                mailMsg.From = new MailAddress(emailMessage.From);
                // Subject and multipart/alternative Body
                mailMsg.Subject = emailMessage.Subject;
                if (emailMessage.HtmlMessage)
                {
                    mailMsg.AlternateViews.Add(AlternateView.CreateAlternateViewFromString(emailMessage.Message, null, MediaTypeNames.Text.Plain));
                    mailMsg.AlternateViews.Add(AlternateView.CreateAlternateViewFromString(emailMessage.Message, null, MediaTypeNames.Text.Html));
                }
                else
                {
                    mailMsg.AlternateViews.Add(AlternateView.CreateAlternateViewFromString(emailMessage.Message, null, MediaTypeNames.Text.Plain));
                }
                // Init SmtpClient and send
                var smtpClient = new SmtpClient(Smtp_Server, 587);
                var credentials = new System.Net.NetworkCredential(Smtp_UserName, Smtp_Password);

                smtpClient.EnableSsl = true;

                smtpClient.Credentials = credentials;
                if (Dont_Send_Emails)
                {
                    emailMessage.SentStatus = SentStatus.NotSent;
                }
                else
                {
                    smtpClient.Send(mailMsg);

                    emailMessage.SentStatus = SentStatus.Sent;
                    emailMessage.Sent_Date = DateTime.Now.ToFileTimeUtc();
                }
                return true;
            }
            catch (Exception ex)
            {
                ex.log("[Error sending email");
                emailMessage.SentStatus = SentStatus.Error;
                return false;
            }
        }
예제 #3
0
 //Refactor into SMTP class
 public bool send(EmailMessage_Post emailMessagePost)
 {
     if (emailMessagePost.isNull())
         return false;
     var emailMessage = new EmailMessage(emailMessagePost);
     return send(emailMessage);
 }
예제 #4
0
 public bool send(string to, string subject, string message, bool htmlMessage)
 {
     var emailMessage = new EmailMessage
                             {
                                 To = to,
                                 From = this.From,
                                 Subject = subject,
                                 Message = message,
                                 HtmlMessage = htmlMessage
                             };
     return send(emailMessage);
 }
예제 #5
0
파일: SendEmails.cs 프로젝트: rbg13/Master
        public bool send(EmailMessage emailMessage)
        {
            if (emailMessage.isNull())
            {
                return(false);
            }

            //emailMessage.Message += TMConsts.EMAIL_DEFAULT_FOOTER;
            emailMessage.Message += Email_Footer;
            Sent_EmailMessages.Add(emailMessage);

            if (emailMessage.From.notValid())
            {
                emailMessage.From = this.From;
            }
            TM_UserData.Current.logTBotActivity("Send Email", "From: {0}    To: {1}    Subject: {2}".format(emailMessage.From, emailMessage.To, emailMessage.Subject));

            try
            {
                if (this.serverNotConfigured())
                {
                    emailMessage.SentStatus = SentStatus.NoConfig;
                    return(false);
                }

                emailMessage.SentStatus = SentStatus.Sending;
                "Sending email:\n  to: {0}\n  from: {0}\n  subject: {0} ".info(emailMessage.To, emailMessage.Subject, emailMessage.Message);
                var mailMsg = new MailMessage();
                // To
                mailMsg.To.Add(new MailAddress(emailMessage.To));
                // From
                mailMsg.From = new MailAddress(emailMessage.From);
                // Subject and multipart/alternative Body
                mailMsg.Subject = emailMessage.Subject;
                if (emailMessage.HtmlMessage)
                {
                    mailMsg.AlternateViews.Add(AlternateView.CreateAlternateViewFromString(emailMessage.Message, null, MediaTypeNames.Text.Plain));
                    mailMsg.AlternateViews.Add(AlternateView.CreateAlternateViewFromString(emailMessage.Message, null, MediaTypeNames.Text.Html));
                }
                else
                {
                    mailMsg.AlternateViews.Add(AlternateView.CreateAlternateViewFromString(emailMessage.Message, null, MediaTypeNames.Text.Plain));
                }
                // Init SmtpClient and send
                var smtpClient  = new SmtpClient(Smtp_Server, 587);
                var credentials = new System.Net.NetworkCredential(Smtp_UserName, Smtp_Password);

                smtpClient.EnableSsl = true;

                smtpClient.Credentials = credentials;
                if (Dont_Send_Emails)
                {
                    emailMessage.SentStatus = SentStatus.NotSent;
                }
                else
                {
                    smtpClient.Send(mailMsg);

                    emailMessage.SentStatus = SentStatus.Sent;
                    emailMessage.Sent_Date  = DateTime.Now.ToFileTimeUtc();
                }
                return(true);
            }
            catch (Exception ex)
            {
                ex.log("[Error sending email");
                emailMessage.SentStatus = SentStatus.Error;
                return(false);
            }
        }
예제 #6
0
        public bool send(EmailMessage emailMessage)
        {
            Sent_EmailMessages.Add(emailMessage);
            try
            {
                if (this.serverNotConfigured())
                {
                    emailMessage.SentStatus = SentStatus.NoConfig;
                    return false;
                }
                if (emailMessage.From.notValid())
                    emailMessage.From = this.From;
                emailMessage.SentStatus = SentStatus.Sending;
                "Sending email:\n  to: {0}\n  from: {0}\n  subject: {0} ".info(emailMessage.To, emailMessage.Subject, emailMessage.Message);
                var mailMsg = new MailMessage();

                emailMessage.Message += "Send by TeamMentor. ".format().lineBefore().lineBefore().line().line();
                // To
                mailMsg.To.Add(new MailAddress(emailMessage.To));
                // From
                mailMsg.From = new MailAddress(emailMessage.From);
                // Subject and multipart/alternative Body
                mailMsg.Subject = emailMessage.Subject;
                if (emailMessage.HtmlMessage)
                {
                    mailMsg.AlternateViews.Add(AlternateView.CreateAlternateViewFromString(emailMessage.Message, null, MediaTypeNames.Text.Plain));
                    mailMsg.AlternateViews.Add(AlternateView.CreateAlternateViewFromString(emailMessage.Message, null, MediaTypeNames.Text.Html));
                }
                else
                {
                    mailMsg.Body = emailMessage.Message;
                }
                // Init SmtpClient and send
                var smtpClient = new SmtpClient(Smtp_Server, 587);
                var credentials = new System.Net.NetworkCredential(Smtp_UserName, Smtp_Password);
                smtpClient.Credentials = credentials;

                smtpClient.Send(mailMsg);

                emailMessage.SentStatus = SentStatus.Sent;
                emailMessage.Sent_Date = DateTime.Now.ToFileTimeUtc();
                return true;
            }
            catch (Exception ex)
            {
                ex.log("[Error sending email");
                emailMessage.SentStatus = SentStatus.Error;
                return false;
            }
        }
예제 #7
0
 //Refactor into SMTP class
 public bool send(EmailMessage_Post emailMessagePost)
 {
     var emailMessage = new EmailMessage(emailMessagePost);
     return send(emailMessage);
 }