Difference between revisions of "Sample Code"

From Hostek.com Wiki
Jump to: navigation, search
(Created page with "==ASP Sample Code== <B>Form to Email samples (Windows server only)</B><br/> <B>ASP samples</B><br/> [http://hostek.com/faq/kb/index.asp?action=recorddetail&rec=90 CDOSYS Emai...")
 
Line 19: Line 19:
 
<B>XML example - filling a table</B><br/>
 
<B>XML example - filling a table</B><br/>
 
[http://hostek.com/sample_code/xmlsample.zip XML Sample]
 
[http://hostek.com/sample_code/xmlsample.zip XML Sample]
 +
 +
<B>ASP.NET 1.1 - code to send email via script</B><br/>
 +
The following code will send an e-mail without authentication using .Net 1.1:
 +
 +
System.Web.Mail.MailMessage msg = new System.Web.Mail.MailMessage();
 +
 +
msg.To = "support@hostek.com"; /* separate the addresses with semi-colons like the following "address1@yahoo.com;address2@hotmail.com;address3@hostek.com" */
 +
 +
msg.From = "test@hostek.com";
 +
 +
msg.BodyFormat = System.Web.Mail.MailFormat.Text;  /* change to System.Web.Mail.MailFormat.Html to use HTML in the body */
 +
 +
msg.Subject = ".Net 1.1 Test e-mail subject"; msg.Body = ".Net 1.1 Test e-mail body";
 +
 +
System.Web.Mail.SmtpMail.SmtpServer = "smtpmailer.hostek.net"; System.Web.Mail.SmtpMail.Send(msg);
 +
 +
Response.Redirect("success.html");  /*redirects the client to a page letting them know the email was sent successfully */
 +
 +
 +
To send using authentication, add the following before the System.Web.Mail.SmtpMail lines:
 +
 +
msg.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserver"] =
 +
"mailX.hostek.com";
 +
msg.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserverport"] = 25;
 +
msg.Fields["http://schemas.microsoft.com/cdo/configuration/sendusing"] = 2;
 +
msg.Fields["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"] = 1;
 +
 +
msg.Fields["http://schemas.microsoft.com/cdo/configuration/sendusername"] =
 +
"username@domain.com";
 +
msg.Fields["http://schemas.microsoft.com/cdo/configuration/sendpassword"] = "password";
  
 
[[Category:ASP.Net Tutorials]]
 
[[Category:ASP.Net Tutorials]]

Revision as of 07:25, 22 November 2012

ASP Sample Code

Form to Email samples (Windows server only)
ASP samples
CDOSYS Email Sample (recommended for ASP use - Windows 2000 and Windows 2003 servers
CDONTS Email Sample ASPMail Email Sample
HTML samples
ntformmail.pl Email Sample
(ntformmail.pl is a modified version of formmail.pl that is commonly used on Unix servers.


Hidden and Visible Counters (NT and Unix)
Visible Counter for ASP pages

Hidden and Visible Counter


XML example - filling a table
XML Sample

ASP.NET 1.1 - code to send email via script
The following code will send an e-mail without authentication using .Net 1.1:

System.Web.Mail.MailMessage msg = new System.Web.Mail.MailMessage();

msg.To = "support@hostek.com"; /* separate the addresses with semi-colons like the following "address1@yahoo.com;address2@hotmail.com;address3@hostek.com" */

msg.From = "test@hostek.com";

msg.BodyFormat = System.Web.Mail.MailFormat.Text; /* change to System.Web.Mail.MailFormat.Html to use HTML in the body */

msg.Subject = ".Net 1.1 Test e-mail subject"; msg.Body = ".Net 1.1 Test e-mail body";

System.Web.Mail.SmtpMail.SmtpServer = "smtpmailer.hostek.net"; System.Web.Mail.SmtpMail.Send(msg);

Response.Redirect("success.html"); /*redirects the client to a page letting them know the email was sent successfully */


To send using authentication, add the following before the System.Web.Mail.SmtpMail lines:

msg.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserver"] = "mailX.hostek.com"; msg.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserverport"] = 25; msg.Fields["http://schemas.microsoft.com/cdo/configuration/sendusing"] = 2; msg.Fields["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"] = 1;

msg.Fields["http://schemas.microsoft.com/cdo/configuration/sendusername"] = "username@domain.com"; msg.Fields["http://schemas.microsoft.com/cdo/configuration/sendpassword"] = "password";