Code Text of VBS File to Execute JMail

By Danny Lesandrini (Send Email)
Posted May 29, 2001



JMail Download
DataFast Consulting
Dean Evans and Associates
Code Text of VBS File to Execute JMail


Code Text of VBS File to Execute JMail

The following code may be copied, pasted into Notepad as a .vbs file. Alternatively, a
sample vbs file, along with the jmail.dll library file, may be downloaded from this site.

' ***************************************************************
' Script To Send JMail Message 
'
' This script will uses COM Automation to access the JMail Object
' Model in order to create and send an Outlook Mail Message.
'
' Dimac w3 JMail is being used by 400.000+ programmers worldwide.
' W3 JMail is based on COM technology and can therefore be called
' from most modern programming languages, though it has most of its
' users in the ASP platform 
'
'
' ***************************************************************
' ***************************************************************
' *****************    VERY VERY IMPORTANT !!!! *****************
'
' In order for this utility to function correctly, JMail must be
' registered on your computer.  Assuming you place the jmail.dll 
' in the Windows System folder, the syntax  for registering the 
' JMail dll is as follows: 
'
'    regsvr32 "C:\Windows\System\jmail.dll" 
'
' For Win NT and Win 2000, the folder is System32 and syntax is:
'
'    regsvr32 "C:\WINNT\System32\jmail.dll" 
'
' ***************************************************************
' ***************************************************************
'
' The attached version of the JMail dll is for personal use only.  
' It is distributed without charge from the Dimac web page, but 
' corporate and enterprise distribution is subject to a fee. Please 
' go to the Dimac web site for more information and code samples.
'
'    http://tech.dimac.net
'
'
' This utility is provided as an example only.  It is not intended 
' to serve as an EMail application and is not supported by DataFast 
' or Dimac.  Use this utility as a learning tool to assist you with 
' mail enabling your VB, VBA and ASP applications.
'
'
' Brief Explanation of Code:
' ---------------------------------------------------------------
' The user is presented with a series of Input Boxes to collect the
' information necessary to create and send the mail item.              
'
'   Server                 Example:  pop.uswest.net                  
'   User Name              Example:  MrYadaUser    (may leave blank)
'   User Password          Example:  123SecretPWD  (may leave blank)
'
'   Recipient  Address     Example:  dan@dea.com                  
'   Message Subject        Example:  So, how have you been?       
'   Message Body Text      Example:  Blah, blah, blah             
'
' ***************************************************************

' Declare Variables (as variants)
Dim objJMail, strFrom, strMsg
Dim strServer, strUID, strPWD
Dim strRecipient , strSubject, strBodyText

' Collect information from user about Server
strServer = InputBox("What is your Mail Server?","JMail")
strUID = InputBox("Enter User Name (optional)", "JMail")
strPWD = InputBox("Enter Password (optional)", "JMail")

' Collect information from user about Message
strMsg = "Enter recipient  mail address." & vbCrLf & "(Format:  dan@dea.com)"
strReceipent = InputBox(strMsg, "JMail", "dan@dea.com")

strMsg = "Enter subject line."
strSubject = InputBox(strMsg, "JMail", "Message from JMail")

strMsg = "Enter message text."
strBodyText = InputBox(strMsg, "JMail", "Wow! JMail works!")

' Create the JMail message Object
set objJMail = CreateOBject( "JMail.Message" )

' Set silent to true as we wish to handle our errors ourself
' And set logging to true to ease any potential debugging
objJMail.silent = true
objJMail.Logging = true

' Most mail servers require a valid email address for the sender
objJMail.From = "test@mydomain.com"
objJMail.FromName = "My Realname"

' Next we have to add some recipients. The addRecipients method
' can be used multiple times. Note: name (2nd param)is optional.
objJMail.AddRecipient strReceipent, strReceipent

' Add additional recipients if desired (disabled here)
'objJMail.AddRecipient "SecondRecip@herDomain.com"

' Provide a subject for the message
objJMail.Subject = strSubject

' The body property is both read and write. If you want to append 
' text to the body you can use this syntax:
'     objJMail.Body = objJMail.Body & "Hello world!"
'
' or you can use objJMail.AppendText "Hello World! " which in many
' cases is easier to use.
objJMail.Body = strBodyText

' There.. we have now succesfully created our message. Now we can 
' either send the message or save it as a draft in a Database. To 
' save the message you would typically use the Message objects Text 
' property to do something like this:
'     SaveMessageDraft( objJMail.Text )
'
' Note that this function call is only an example. The function
' does not exist by default, you have to create it yourself.

If Len(strUID) Then objJMail.MailServerUserName = strUser
If Len(strPWD) Then objJMail.MailServerPassWord = strPassword

' To send the message, you use the Send() method, which takes one
' parameter that should be your mail server's address. To capture
' any potential errors, we wrap the call in an IF statement
'
If Not objJMail.Send(strServer) then
    MsgBox objJMail.log
Else
    MsgBox "Message sent successfully!"
End If

As may be seen from the code sample above, JMail is really quite easy to use.
The above script is displayed as text of a .vbs script file, but it works equally
well in an ASP page, from VBA code in an Access database and from a VB project.

If you need to add messaging capabilities to your application, you owe it to
yourself to check out this powerful and easy to use COM object.

Page 1 of 1


Comment and Contribute

Your name/nickname

Your email

(Maximum characters: 1200). You have characters left.