当前位置: 首页>>代码示例>>C#>>正文


C# MailMessage.SendAsync方法代码示例

本文整理汇总了C#中System.Net.Mail.MailMessage.SendAsync方法的典型用法代码示例。如果您正苦于以下问题:C# MailMessage.SendAsync方法的具体用法?C# MailMessage.SendAsync怎么用?C# MailMessage.SendAsync使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Net.Mail.MailMessage的用法示例。


在下文中一共展示了MailMessage.SendAsync方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: QuickMail

        /// <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;
        }
开发者ID:stupidArnob,项目名称:DevMVCComponent,代码行数:37,代码来源:Mailer.cs

示例2: SendAsync

        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
        }
开发者ID:ChuangYang,项目名称:Z.ExtensionMethods,代码行数:10,代码来源:MailMessage.SendAsync.cs

示例3: should_send_async_and_call_back

        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);
        }
开发者ID:CodeFork,项目名称:RazorEmail,代码行数:15,代码来源:EmailExtensionTest.cs

示例4: Send

        /// <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) {

            }
        }
开发者ID:stupidArnob,项目名称:DevMVCComponent,代码行数:28,代码来源:Mailer.cs

示例5: should_send_async

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

            message.SendAsync();
        }
开发者ID:CodeFork,项目名称:RazorEmail,代码行数:6,代码来源:EmailExtensionTest.cs


注:本文中的System.Net.Mail.MailMessage.SendAsync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。