Welcome to the CSIG, a Special Interest Group of the ACGNJ. This is an exciting time for the C Language programming since Microsoft now has 4 different language compilers: C++, C++ Express, C-Sharp, and C-Sharp Express. These are all capable of creating Windows (tm) programs.
This month I will continue the discussion on the batch or bulk emailer program called "Bmailer". Additional features have been added that affect the "Look and Feel" of the application. Remember that the program uses text files for input. The first is the recipients email addresses that could contain hundreds of addresses. The second is a template text file that will be sent out to each recipient.
Two new buttons have been added that allow the two files to be edited when you catch a spelling error or wrong address. Logic has now been added to allow for HTML statements and formating. A checkbox now optionally adds a greeting like "Hi Frank," at the beginning of each email. These and other code changes fall under the "General Visual Studio .NET programming" category.
When the "Send Mail" button is clicked, the application starts sending out the emails to the given SMTP provider. Since some providers don't allow high speed batch processing, an optional 30 second delay is provided between outputs.
Here are some of the topics that are included in the discussion.
1. Building an application using Visual Studio 2008 SP1. |
2. Building a "CLI" .Net program. |
3. Using the Integrated Editor to create Buttons. |
4. ... Listboxes and Textboxes. |
5. ... Checkboxes. |
6. ... Timers and other logic. |
7. Applying and changing Color on the window. |
8. Calling an external program such as Word or Notepad. |
9. Communicating with an SMTP server. (Simple Mail Transfer Protocol) |
10. Flow charts and program logic. |
There are a number of ways to refer to this compiler and code. Here's what Wikipedia says: The Common Language Infrastructure (CLI) is an open specification developed by Microsoft that describes the executable code and runtime environment that form the core of the Microsoft .NET Framework. The specification defines an environment that allows multiple high-level languages to be used on different computer platforms without being rewritten for specific architectures.
Microsoft .Net Framework 2.0 |
C++ 7.0 |
.Net 2.0 |
CLI |
Common Language Infrastructure |
Managed |
public: // Fill the template list box void GetTemplate(String ^ filename) { // Open the file to read from. StreamReader ^sr = gcnew StreamReader(filename); if (sr != nullptr) { String ^s; while ((s = sr->ReadLine()) != nullptr) { Template->Items->Add(s); } sr->Close(); } } private: System::Void SendMail_Click(System::Object^ sender, System::EventArgs^ e) { timer1->Interval = 1000; timer1->Enabled = true; SendMail->Enabled = false; CurrentRecip = 0; SentCount = 0; AbortFlag = false; Abort->Enabled = true; Recipients->ClearSelected(); return; } private: System::Void timer1_Tick(System::Object^ sender, System::EventArgs^ e) { timer1->Enabled = false; timer1->Interval = Timer30->Checked ? 30000 : 1000; if (CurrentRecip < Recipients->Items->Count) { Recipients->SetSelected(CurrentRecip, true); if ( 0 == DoSendMail() ) ++SentCount; SentInfo->Text = String::Format("{0} emails sent.", SentCount); } ++CurrentRecip; if (AbortFlag || (CurrentRecip >= Recipients->Items->Count)) SendMail->Enabled = true; else timer1->Enabled = true; } // Launch the application for the Recipients or the Template. // Change the color of the application to White when its disabled. private: enum System::Windows::Forms::DialogResult Launch_Edit(String ^ arg) { System::Windows::Forms::DialogResult result; Process ^ mEdit = gcnew Process(); mEdit->StartInfo->FileName = arg; mEdit->StartInfo->Verb = "Open"; this->BackColor = System::Drawing::Color::FromKnownColor(System::Drawing::KnownColor::Window); this->Enabled = false; mEdit->Start(); // Launch the program mEdit->WaitForExit(); // and wait for it to be closed. this->Enabled = true; this->Activate(); result = MessageBox::Show("Reload File ?", "Reload", MessageBoxButtons::YesNo, MessageBoxIcon::Question); this->BackColor = Color::PaleTurquoise; return result; }
Note: typically you will need the MS C++ Redistribution Package to run programs on any computer.