Sample code for Active Server Component (ASPMail)

Every HamaraHost.com Windows Web Hosting package comes with the ASPMail component, which allows you to send SMTP mail directly from a Web page.

You can easily customise our sample script and put it up on your website. You would, however, need to change the Email Address in the field Mailer.FromAddress to any Email Address on the Domain on which you are
incorporating the script. For example, if your Domain Name is abc.com, then you need to define the Email Address as user@abc.com. This Email Address need not be existing on the Mail Server of abc.com, however, the domain name in the Mailer.FromAddress field has to be yours. Thus, you may use an Email Address like Do_Not_reply@abc.com as the Mailer.FromAddress.

The Email Address in the Mailer.AddRecipient field needs to be changed to your Email Address, where you wish to receive Emails submitted through the web page.

Sample Script

<%
Set Mailer = Server.CreateObject("SMTPsvg.Mailer")
Mailer.FromName = "Testing"
Mailer.FromAddress= "user@abc.com"
Mailer.RemoteHost = "localhost"
Mailer.AddRecipient "Testing User", "youremail"
Mailer.Subject = "Testing"
Mailer.BodyText = "Testing"
if Mailer.SendMail then
Response.Write "Mail sent..."
else
Response.Write "Mail send failure. Error was " & Mailer.Response
end if
%>

Sample code for using CDO in ASP

Originally known as Active Messaging, the Collaboration Data Objects (CDO) library allows users to send mails through ASP Scripts.

Collaboration Data Objects (CDO) is Microsoft’s technology for building messaging or collaboration applications or adding these capabilities to existing applications. Part of the Microsoft Exchange Server product, CDO has evolved from what Microsoft formerly called Object Linking and Embedding Messaging and, more recently, Active Messaging.

You can use the sample script provided by HamaraHost.com and tweak it a bit to your requirements, to accept feedback from your website visitors and get the results emailed to you.

You would need to change the Email Address in the field myMail.From to any Email Address on the domain name on which you are incorporating the script.

Example:

If your Domain Name is abc.com, then you would define the From Email Address as some-name@abc.com. This Email Address need not be existing on the Mail Server of abc.com, however, the domain name in the myMail.From field has to be yours. You may use an Email Address such as Do_Not_reply@abc.com.

The Email Address in the myMail.To field needs to be changed to your Email Address, where you wish to receive Emails submitted through the form.

Sample Script

<%
Set myMail=CreateObject("CDO.Message")
myMail.Subject="Sending email with CDO"
myMail.From="something@domainname.com"
myMail.To="xyz@abc.com"
myMail.TextBody="This is a message."
myMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing")=2
'Name or IP of remote SMTP server
myMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver")="localhost"
'Server port
myMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport")=25
myMail.Configuration.Fields.Update
myMail.Send
%>

Note

The body of the mail should not have bare linefeeds (\n). If a bare linefeed is detected, the SMTP service of Microsoft IIS6 (the Web Server running on HamaraHost.com‘s Windows servers) will stop delivering any mail and the mails will get struck in the SMTP queue. This is because Microsoft IIS6 strictly follows Internet e-mail standards; and these standards forbid the presence of bare linefeed characters in e-mail messages.

Example:

myMail.TextBody="Thank you for contacting us. We shall get back to you shortly.\n
Kind regards\n
abc.com"

In the above case, bare linefeeds (\n) are being used. Instead of \n, you need to use \r\n (carriage-return, line-feed). Hence, the correct usage would be:

myMail.TextBody="Thank you for contacting us. We shall get back to you shortly.\r\n
Kind regards\r\n
abc.com"

Sample code for ASPSmartUpload component

ASPSmartUpload is an Active Server component which enables an ASP application to accept, save and manipulate files uploaded through a browser. The files are uploaded via a HTML POST form with one or more <INPUT TYPE=FILE> tags. The <FORM> tag must contain the attribute ENCTYPE=”multipart/form-data”. All HamaraHost.com Windows Hosting packages have support enabled for ASPSmartUpload component. You can use the sample script provided below and tweak it a bit to suit your requirements.

Upload Script (Upload.asp)

<%
// Variables

Dim mySmartUpload
Dim intCount

// Object creation

Set mySmartUpload = Server.CreateObject("aspSmartUpload.SmartUpload")

// Upload

mySmartUpload.Upload

// Save the files in a folder on the web server

intCount = mySmartUpload.Save("C:\WHB\Sites\yourdomainname.com\datafiles")

// Display the number of files uploaded

Response.Write(intCount & " file(s) uploaded to C:\WHB\Sites\yourdomainname.com\datafiles")
%>

HTML form for uploading up to 3 files

<HTML>
<BODY BGCOLOR="#FFFFFF">
<FORM METHOD="POST" ENCTYPE="multipart/form-data" ACTION="Upload.asp">
<INPUT TYPE="FILE" NAME="FILE1" SIZE="50"><BR>
<INPUT TYPE="FILE" NAME="FILE2" SIZE="50"><BR>
<INPUT TYPE="FILE" NAME="FILE3" SIZE="50"><BR>
<INPUT TYPE="SUBMIT" VALUE="Upload!">
</FORM>
</BODY>
</HTML>

Sample code for ASPUpload component

ASPUpload is an Active Server component which enables an ASP application to accept, save and manipulate files uploaded with a browser. The files are uploaded via an HTML POST form with one or more <INPUT TYPE=FILE> tags. The <FORM> tag must contain the attribute ENCTYPE=”multipart/form-data”. All HamaraHost.com Windows Hosting packages have support enabled for ASPUpload component. You can use the sample script provided below and tweak it a bit to suit your requirements.

Upload Script (Upload.asp)

<%
Set Upload = Server.CreateObject("Persits.Upload")
Count = Upload.Save("C:\WHB\Sites\yourdomainname.com\datafiles")
Response.Write Count & " file(s) uploaded to C:\WHB\Sites\yourdomainname.com\datafiles"
%>

HTML form for uploading up to 3 files

<HTML>
<BODY BGCOLOR="#FFFFFF">
<FORM METHOD="POST" ENCTYPE="multipart/form-data" ACTION="Upload.asp">
<INPUT TYPE="FILE" NAME="FILE1" SIZE="50"><BR>
<INPUT TYPE="FILE" NAME="FILE2" SIZE="50"><BR>
<INPUT TYPE="FILE" NAME="FILE3" SIZE="50"><BR>
<INPUT TYPE="SUBMIT" VALUE="Upload!">
</FORM>
</BODY>
</HTML>