Example #1
0
        /// <summary>
        /// When task is started mail will be sent asynchronously 
        /// </summary>
        /// <param name="body"></param>
        /// <param name="sub"></param>
        /// <param name="to"></param>
        /// <param name="isHtml"></param>
        /// <param name="send"></param>
        /// <param name="NotifyDeveloper"></param>
        /// <param name="NotifyAdmin"></param>
        /// <returns></returns>
        public Task QuickMail(string body, string sub, string to = "", bool isHtml = true, bool send = true, bool NotifyDeveloper = false, bool NotifyAdmin = false)
        {
            Task t = new Task(() => {
                var mail = new MailMessage();
                mail.Subject = sub;
                mail.Body = body;
                mail.IsBodyHtml = isHtml;
                if (send) {
                    if (to != "" && to != null) {
                        mail.To.Add(to);
                    }
                    if (NotifyAdmin && Config.AdminEmail != null) {
                        mail.To.Add(Config.AdminEmail);
                    }
                    if (NotifyDeveloper && Config.DeveloperEmail != null) {
                        mail.To.Add(Config.DeveloperEmail);
                    }
                }

                mail.SendAsync();
            });
            if (send) {
                t.Start();
            }
            return t;
        }
        public void SendAsync()
        {
            var token = new object();

            // Type
            var @this = new MailMessage("[email protected]", "[email protected]", "Fizz", "Buzz");

            // Examples
            @this.SendAsync(token); // Send a mail async
        }
        public void should_send_async_and_call_back()
        {
            var message = new MailMessage("[email protected]", "[email protected]", "subject", "body");

            var wait = new ManualResetEvent(false);
            message.SendAsync((x,client)=>
                                  {
                                      Assert.AreEqual("test1State", x);
                                      Trace.WriteLine(x);
                                      wait.Set();
                                  } , "test1State");

            var result = wait.WaitOne(TimeSpan.FromSeconds(2));
            Assert.IsTrue(result);
        }
Example #4
0
        /// <summary>
        /// Calls SetMailDefaults first.
        /// </summary>
        /// <param name="mail"></param>
        /// <param name="subject"></param>
        /// <param name="to"></param>
        public void Send(MailMessage mail, string subject = "",  string to = "")
        {
            mail = SetMailDefaults(mail);
            if (subject != null && subject == "") {
                mail.Subject = subject;
            }

            if (to != null && to != "") {
                mail.To.Add(to);
            }

            try {
                new Thread(() => {
                    if (SEND_ASY)
                        mail.SendAsync();
                    else
                        mail.Send();
                }).Start();
            } catch (Exception) {

            }
        }
        public void should_send_async()
        {
            var message = new MailMessage("[email protected]", "[email protected]", "subject", "body");

            message.SendAsync();
        }