C# // Create SMTP object Smtp mailer = new Smtp(); // Set the message fields. mailer.From.AsString = "jdoe@domain.com"; mailer.To.AsString = "bill@domain2.com"; mailer.Subject = "Hi"; mailer.BodyPlainText = "This is test message"; // Starts logging SMTP activities into a file. mailer.Log.Enabled = true; mailer.Log.Filename = @"C:\log.txt"; mailer.Log.Clear(); // Specify the server to use. If your server does not require authentication, // just omit both last parameters. mailer.SmtpServers.Add("mail.domain.com", "jdoe", "secret"); // Attempt to connect. mailer.Connect(); // Display the host name of the server the connection was established with. Console.WriteLine("Connected to " + mailer.SmtpServers[mailer.GetCurrentSmtpServerIndex()].Name); // Make sure all the recipients are ok. if (mailer.TestSend(SendFailureThreshold.AllRecipientsFailed) != TestSendResult.OK) { Console.WriteLine("No recipients can receive the message."); }// Show refused recipients if any else if (mailer.GetRefusedRecipients().Count > 0) { Console.WriteLine("The following recipients failed: " + mailer.GetRefusedRecipients().ToString()); } else { Console.WriteLine("All recipients are ok. Will send the message now."); // Send e-mail. If it cannot be delivered, bounce will // arrive to bounce@domain3.com, not to joe@domain1.com mailer.Send("bounce@domain.com", (string)null); Console.WriteLine("Sent to: " + mailer.GetAcceptedRecipients().ToString()); } // Disconnect from the server mailer.Disconnect();
VB.NET ' Create SMTP object Dim mailer As New Smtp ' Set the message fields. mailer.From.AsString = "jdoe@domain.com" mailer.To.AsString = "bill@domain2.com" mailer.Subject = "Hi" mailer.BodyPlainText = "This is test message" ' Starts logging SMTP activities into a file. mailer.Log.Enabled = True mailer.Log.Filename = "C:\log.txt" mailer.Log.Clear() ' Specify the server to use. If your server does not require authentication, ' just remove last 2 parameters. mailer.SmtpServers.Add("mail.domain.com", "jdoe", "secret") ' Attempt to connect. mailer.Connect() ' Display the host name of the server the connection was established with. Console.WriteLine("Connected to " + mailer.SmtpServers(mailer.GetCurrentSmtpServerIndex()).Name) ' Make sure all the recipients are ok. If mailer.TestSend(SendFailureThreshold.AllRecipientsFailed) <> TestSendResult.OK Then Console.WriteLine("No recipients can receive the message.") Else ' Show refused recipients if any If mailer.GetRefusedRecipients().Count > 0 Then Console.WriteLine("The following recipients failed: " & mailer.GetRefusedRecipients().ToString()) Else Console.WriteLine("All recipients are ok. Will send the message now.") ' Send e-mail. If it cannot be delivered, bounce will ' arrive to bounce@domain3.com, not to joe@domain1.com mailer.Send("bounce@domain.com", CType(Nothing, String)) Console.WriteLine("Sent to: " + mailer.GetAcceptedRecipients().ToString()) End If End If ' Disconnect from the server mailer.Disconnect()
MFC(微软基础类库)是专门为windows设计的一个用于开发图形用户界面的类库。MFC或多或少使用了面向对象的方法包装了Win32的API,正因如此,这些API有时是C++,有时是C,甚至是C和C++的混合体。
Qt这个C++的图形库由Trolltech在1994年左右开发。它可以运行在Windows、Mac OSX、Unix、还有像Sharp Zaurus这类嵌入式系统中,Qt是完全面向对象的。Document/View modelMFC编程需要使用Document/View模式以及模板(template),如果不使用的话,编程将变得异常困难。而且模板(template)设定了固定的结构,若所需结构乃模板未定义的结构,则编程难。例如,划分一区域使显示两个视图(view)于两个文档(document)。还有一个经常的问题是:模板(template)创建了视图(view)却无法访问(access)它,文档(document)要做完所有事情,但是这经常会出现问题。 这种数据和视图分开的设计模式也是一种不错的模式,不应该成为否定MFC的理由。Qt不强制使用任何设计模式,如果你认为恰当,使用Document/view没有任何问题,不使用也没有任何问题。