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


C# System.Net.Mail.SmtpClient.SendAsync方法代码示例

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


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

示例1: output

        public override string output(System.Collections.ArrayList columnHeaders,
            System.Collections.ArrayList rows,
            System.Collections.Hashtable rowLengthLookup)
        {
            //email://[email protected]/Trial Signup Report

            Regex regex = new Regex(
              "(?<Proto>[a-zA-Z]*)://(?<ToAddress>[[email protected]_-]*)/(?<Subject"+
              ">[\\[email protected]_-]*)",
            RegexOptions.CultureInvariant
            | RegexOptions.Compiled
            );

            if (regex.IsMatch(PropertyBag.GetProperty("data.output")))
            {
                Match match = regex.Match(PropertyBag.GetProperty("data.output"));
                string emailAddress = match.Groups[2].Value;
                string subject = match.Groups[3].Value;

                Console.WriteLine("Sending email to: " + emailAddress);
                string bodySrc = "";

                if (PropertyBag.GetProperty("data.html", "false").ToLower() == "true")
                {
                    OutputMethod_HTML output = new OutputMethod_HTML();
                    bodySrc = output.output(columnHeaders, rows, rowLengthLookup);
                }
                else {
                    OutputMethod_TXTOnly output = new OutputMethod_TXTOnly();
                    bodySrc = output.output(columnHeaders, rows, rowLengthLookup);
                }

                System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(
                    PropertyBag.GetProperty("mail.fromaddress", "[email protected]"),
                    emailAddress,
                    subject,
                    bodySrc);

                if (PropertyBag.GetProperty("data.html", "false").ToLower() == "true")
                    message.IsBodyHtml = true;

                System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient(
                    PropertyBag.GetProperty("mail.smtpserver", "127.0.0.1"), 25);

                client.SendCompleted += (a, b) =>
                {
                    Console.WriteLine("[ERROR] Failed to send email.");
                };

                client.SendAsync(message, message);

            }

            return "";
        }
开发者ID:andrewjc,项目名称:sqlconsole,代码行数:55,代码来源:OutputMethod_Email.cs

示例2: SendEmail

 public string SendEmail()
 {
     string result = "";
     try
     {
         System.Net.Mail.MailMessage mail = CreateMail();
         System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient(host);
         smtp.Port = port;
         smtp.Timeout = 9999;
         smtp.Credentials = new System.Net.NetworkCredential(from, password);
         smtp.SendAsync(mail, null);
         smtp.SendCompleted += new System.Net.Mail.SendCompletedEventHandler(smtp_SendCompleted);
         result = "ok";
     }
     catch (Exception ex)
     {
         result = ex.Message.ToString();
     }
     return result;
 }
开发者ID:AlanWyu,项目名称:WYTools,代码行数:20,代码来源:WYEmail.cs


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