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


C# SmtpClient.TestRecipients方法代码示例

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


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

示例1: btnSimple_Click

        private void btnSimple_Click(object sender, System.EventArgs e)
        {
            if( textFrom.Text.Length == 0 )
            {
                MessageBox.Show( "Please input From, the format can be [email protected] or Tester<[email protected]>" );
                return;
            }

            int to_count = lstTo.Items.Count;
            if( to_count == 0 )
            {
                MessageBox.Show( "please add a recipient at least!" );
                return;
            }

            MessageBox.Show(
                "Simple Send will send email with single thread, the code is vey simple.\r\nIf you don't want the extreme performance, the code is recommended to beginer!" );

            btnSend.Enabled = false;
            btnSimple.Enabled = false;
            btnAdd.Enabled = false;
            btnClear.Enabled = false;
            btnAddTo.Enabled = false;
            btnClearTo.Enabled = false;
            chkTestRecipients.Enabled =false;

            btnCancel.Enabled = true;
            m_bcancel = false;

            int sent = 0;
            for( sent = 0; sent < to_count; sent++ )
            {
                lstTo.Items[sent].SubItems[2].Text = "Ready";
            }

            m_ntotal = to_count;
            m_nsent = 0;
            m_nsuccess = 0;
            m_nfailure = 0;
            status.Text = String.Format( "Total {0}, Finished {1}, Succeeded {2}, Failed {3}",
                m_ntotal, m_nsent, m_nsuccess, m_nfailure );

            sent = 0;
            while( sent < to_count && !m_bcancel)
            {
                Application.DoEvents();
                int index = sent;
                sent++;
                //For evaluation usage, please use "TryIt" as the license code, otherwise the
                //"invalid license code" exception will be thrown. However, the object will expire in 1-2 months, then
                //"trial version expired" exception will be thrown.

                //For licensed uasage, please use your license code instead of "TryIt", then the object
                //will never expire
                SmtpMail oMail = new SmtpMail("TryIt");
                SmtpClient oSmtp = new SmtpClient();
                oSmtp.Tag = index;
                //To generate a log file for SMTP transaction, please use
                //oSmtp.LogFileName = "c:\\smtp.log";

                string err = "";
                try
                {
                    oMail.Reset();
                    //If you want to specify a reply address
                    //oMail.Headers.ReplaceHeader( "Reply-To: <[email protected]>" );

                    //From is a MailAddress object, in c#, it supports implicit converting from string.
                    //The syntax is like this: "[email protected]" or "Tester<[email protected]>"

                    //The example code without implicit converting
                    // oMail.From = new MailAddress( "Tester", "[email protected]" )
                    // oMail.From = new MailAddress( "Tester<[email protected]>" )
                    // oMail.From = new MailAddress( "[email protected]" )
                    oMail.From = textFrom.Text;

                    //To, Cc and Bcc is a AddressCollection object, in C#, it supports implicit converting from string.
                    // multiple address are separated with (,;)
                    //The syntax is like this: "[email protected], [email protected]"

                    //The example code without implicit converting
                    // oMail.To = new AddressCollection( "[email protected], [email protected]" );
                    // oMail.To = new AddressCollection( "Tester1<[email protected]>, Tester2<[email protected]>");

                    string name, address;
                    ListViewItem item = lstTo.Items[index];
                    name = item.Text;
                    address = item.SubItems[1].Text;

                    oMail.To.Add( new MailAddress( name, address ));

                    oMail.Subject = textSubject.Text;
                    oMail.Charset = m_arCharset[lstCharset.SelectedIndex,1];

                    //replace keywords in body text.
                    string body = textBody.Text;
                    body = body.Replace( "[$subject]", oMail.Subject );
                    body = body.Replace( "[$from]", oMail.From.ToString());
                    body = body.Replace( "[$name]", name );
                    body = body.Replace( "[$address]", address );
//.........这里部分代码省略.........
开发者ID:DirkViljoen,项目名称:eSalon,代码行数:101,代码来源:Form1.cs


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