本文整理汇总了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 );
//.........这里部分代码省略.........