ANSMTP Developers Center > Using ANSMTP in WSH/VBScript/JScript

Introduction

ANSMTP is a SMTP component which supports all operations of SMTP/ESMTP protocols (RFC 821, RFC 822, RFC 2554). This tutorial covers the basics of sending email with ANSMTP in WSH/VBScript/JScript.

Installation and Deployment

You should download the ansmtp installer and install it on your machine at first. If you want to distribute or deploy ansmtp without ansmtp installer, please click here to learn more.

Create object instance

Use CreateObject in VBS and new ActiveXObject in JScript to create object instances.

[vbs]
Dim oSmtp
Set oSmtp = CreateObject("ANSMTP.OBJ")
[jscript]
var oSmtp = new ActiveXObject("ANSMTP.OBJ");

Simple project to send email

The following sample demonstrates how to send email in VBS.

[VBS]
Dim oSmtp
set oSmtp = CreateObject("ANSMTP.OBJ")

Sub Send( From, Recipient, Subject, Body, Server )
  NORMAL_RECIPIENT = 0
  COPY_RECIPIENT = 1
  BLIND_COPY_RECIPIENT = 2

  TEXT_PLAIN = 0
  TEXT_HTML = 1	

  oSmtp.RegisterKey = "Your license key"
  oSmtp.Reset
  oSmtp.FromAddr = From
  oSmtp.Subject = Subject
  oSmtp.BodyFormat = TEXT_PLAIN
  oSmtp.BodyText = Body
  oSmtp.ServerAddr = Server

  oSmtp.AddRecipient Recipient, Recipient, NORMAL_RECIPIENT
  
  ' | add cc recipient
  ' | oSmtp.AddRecipient "test", "test@hotmail.com", COPY_RECIPIENT
	
  ' | add bcc recipient
  ' | oSmtp.AddRecipient "test", "test@hotmail.com", BLIND_COPY_RECIPIENT

  ' | ESMTP authentication
  ' | oSmtp.UserName = "your user name"
  ' | oSmtp.Password = "your password"
	
  ' | -- add file attachment -- |
  ' oSmtp.AddAttachment "c:\test.doc" 

  If oSmtp.SendMail() = 0 Then
    WScript.Echo "Sending email to " & Recipient & " succeeded!"
  Else
    WScript.Echo oSmtp.GetLastErrDescription()
  End If
End Sub

WScript.Echo "Please edit this file and input sender, recipient, subject, body and smtp server" 
'Send "dennis@hotmail.com", "support@adminsystem.net", "test subject", "test body", "127.0.0.1"

More samples

Please refer to VBSCRIPT/JSCRIPT samples in ANSMTP installation package.

Free Email Support

Not enough? Please contact our technical support team.

Support@EmailArchitect.NET
VIP@EmailArchitect.NET(Registered User)

Remarks
We usually reply emails in 24hours. The reason for getting no response is likely that your smtp server bounced our reply. In this case, please try to use another email address to contact us. Your Hotmail or Yahoo email account is recommended.



2001-2008 © Copyright AdminSystem Software Limited. All rights reserved.   About us  Site Map