Have you ever wondered how an email message is programmatically sent out from an application? Here I will show three different ways that sent email can be coded in different software platforms.
The first programming snippet comes from a Windows Phone mobile app. It’s actually quite simple. This is for Windows Phone 8 and the C# Sharp coding. An email account needs to first be set up on the phone.
- view plainprint?
-
- EmailComposeTask emailComposeTask = new EmailComposeTask();
-
-
- emailComposeTask.Subject = "test subject";
-
- emailComposeTask.Body = "test message";
-
- emailComposeTask.To = "[email protected]";
-
- emailComposeTask.Cc = "[email protected]";
-
- emailComposeTask.Bcc = "[email protected]";
-
-
- emailComposeTask.Show();
Next, I will show how to transmit an email in PHP coding. This is taken from the email contact page on my website and it works very reliably. This does not require an email client to be set up.
- <?php
-
- session_start();
-
-
- include("simple-php-captcha.php");
-
-
- $flagvar = 0;
- $flagvar1 = 0;
- $flagvar2 = 0;
- $flagvar3 = 0;
- $flagvarx = 0;
-
-
-
- $_SESSION['captcha'] = captcha();
-
-
-
- if ($_POST['submit_email']) {
-
-
- if(strlen($_POST['EMAIL']) <= 0) {
- $flagvar1 = 1;
- $flagvar = 1;
- } else if (!preg_match('/^[^0-9][a-zA-Z0-9_]+([.][a-zA-Z0-9_]+)*[@][a-zA-Z0-9_]+([.][a-zA-Z0-9_]+)*[.][a-zA-Z]{2,4}$/', $_POST['EMAIL'])) {
- $flagvar1 = 1;
- $flagvar = 1;
- }
-
- if ( emptyempty($_POST['SUBJECT']) ) {
- $flagvar2 = 1;
- $flagvar = 1;
- }
-
- if ( emptyempty($_POST['MESSAGEBOARD']) ) {
- $flagvar3 = 1;
- $flagvar = 1;
- }
-
-
- if ( $_REQUEST['skip_CaptchaCode'] === $_SESSION['firstcaptcha'] && $flagvar == 0 ) {
-
-
- $text = strip_tags($_POST['MESSAGEBOARD']);
-
-
- $text = $text."\n\nEmail Sender: ".$_POST['EMAIL'];
-
- $headers = "";
-
-
- mail('[email protected]', $_POST['SUBJECT'], $text, $headers);
-
-
-
- header("Location: http://www.analyzohiosoftware.com/email-verify.html");
-
- }
-
-
- if ( $_REQUEST['skip_CaptchaCode'] != $_SESSION['firstcaptcha'] ) {
- $flagvarx = 1;
- }
-
- }
-
- ?>
Lastly, I will show email programming to send something from a Corel Paradox application. Like the Windows Phone example, this requires an email client to be set up.
- method pushButton(var eventInfo Event)
- var
- ;
- EmailCounter Smallint
- tblVar Table
- tc Tcursor
- m MAIL
- emailvar String
- endVar
-
-
- ;
- setMouseShape(MouseWait,TRUE)
-
-
- ;
- ;
- if tc.open(":PDOXDATA:EmailBlast.db") then
-
- ;
- m.logon("MyPassword", "MyMailProfile")
-
- ;
- tc.edit()
-
- ;
- tc.home()
-
- ;
- EmailCounter = 0
-
- ;
- ;
- while NOT tc.eot()
-
- ;
- ;
- if (tc."Finished" <> "y") then
-
- ;
- m.addAddress(tc."E-mail")
- ;
- m.setSubject("An Email Blast")
- ;
- m.setMessage("Here is an email blast we are sending out…success is expected…")
- ;
- m.addAttachment("c:\\document_folder\\sample.doc")
- ;
- m.send()
-
- ;
- m.emptyAddresses()
- m.emptyAttachments()
-
- ;
- tc."Finished" = "y"
-
- ;
- EmailCounter = EmailCounter + 1
-
- ;
- endif
-
-
- ;
- tc.nextRecord()
-
-
- ;
- ;
- if (EmailCounter > 25) then
- EmailCounter = 0
- msgStop("Message", "Click to continue after these 25 emails went out...")
- endif
-
- ;
- endWhile
-
- ;
- tc.endEdit()
- ;
- tc.close()
-
- ;
- m.logoff()
-
- ;
- ;
- endif
-
-
-
-
- ;
- setMouseShape(MouseArrow,TRUE)
-
-
-
- EndMethod
The three examples described here generally follow the same idea for programmatically constructing sent email. This is one of the most useful skills a developer can learn in today’s world. Whether it is needed for a smart phone app, web page or desktop application, it’s a skill one can't do without.