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


C# SmtpClient.Dispose方法代码示例

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


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

示例1: EmailAlert

    public static bool EmailAlert(string to_add, string from_add, string em_sub, string em_bd, string smtp_server = null, string sAttachment = null)
    {
        int i = 0;
        string[] sTempA = null;
        SmtpClient SmtpMail = new SmtpClient();
        MailMessage MailMsg = new MailMessage();

        sTempA = to_add.Split(',');

        try
        {
            for (i = 0; i < (sTempA.Length -1); i++)
            {
                MailMsg.To.Add(new MailAddress(sTempA[i]));
            }

            MailMsg.From = new MailAddress(from_add);
            MailMsg.Subject = em_sub.Trim();
            MailMsg.Body = em_bd.Trim() + Environment.NewLine;

            if (sAttachment != null)
            {
                Attachment MsgAttach = new Attachment(sAttachment);
                MailMsg.Attachments.Add(MsgAttach);

                if (smtp_sender == null)
                {
                    // default
                    SmtpMail.Host = "";
                }
                else
                {
                    SmtpMail.Host = smtp_sender;
                }
                SmtpMail.Send(MailMsg);
                MsgAttach.Dispose();
            }
            else
            {
                SmtpMail.Host = smtp_sender;
                SmtpMail.Send(MailMsg);
            }
            return true;
        }
        catch (Exception ex)
        {
            sTempA = null;
            SmtpMail.Dispose();
            MailMsg.Dispose();
            //Console.WriteLine(ex);
            return false;
        }
    }
开发者ID:pchnet,项目名称:SQLServer,代码行数:53,代码来源:al.cs

示例2: TextAlert

    public static bool TextAlert(string body, string textAlert = null)
    {
        // If established:
        if (textAlert == null)
        {
            textAlert = "";  // Default
        }

        bool check = false;
        string smtp_sender = "";
        string from = "";
        SmtpClient smtpcl = new SmtpClient(smtp_sender);

        if (body.Count() > 140)
        {
            string b;
            int start = 0;
            float bodycount = (body.Count() / 140);
            if (((body.Count() % 140) != 0))
            {
                for (int i = 1; i <= (bodycount + 1); i++)
                {
                    if (i == (bodycount + 1))
                    {
                        b = body.Substring(start, (body.Count() - start));
                    }
                    else
                    {
                        b = body.Substring(start, 140);
                    }

                    try
                    {
                        smtpcl.Send(from, textAlert, "", b);
                        check = true;
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Text alert failed.  Error: " + ex.ToString());
                    }
                    start = start + 140;
                }
            }
            else
            {
                for (int i = 1; i <= bodycount; i++)
                {
                    b = body.Substring(start, 140);
                    try
                    {
                        smtpcl.Send(from, textAlert, "", b);
                        check = true;
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Text alert failed.  Error: " + ex.ToString());
                    }
                    start = start + 140;
                }
            }
        }
        else
        {
            try
            {
                smtpcl.Send(from, textAlert, "", body);
                check = true;
            }
            catch (Exception ex)
            {
                Console.WriteLine("Text alert failed.  Error: " + ex.ToString());
            }
        }

        smtpcl.Dispose();
        return check;
    }
开发者ID:pchnet,项目名称:SQLServer,代码行数:77,代码来源:al.cs


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