Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Other Programming > VBScript
VBScript For questions and discussions related to VBScript.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VBScript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old February 2nd, 2005, 01:14 AM
vc1 vc1 is offline
Registered User
Join Date: Feb 2005
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default Sending mails through vbs file


I have vbs file mailout.vbs,I am using this file to sent out email messge.I add it under scheduled tasks.It runs successfully but I am not receiving any emails.SMTP service is running on the machine.

Do I need to do any settings for mail server?Please advice.

The code for mailout.vbs is:

' Mailout using CDONTS.NewMail

' Declare all variables.
Option Explicit
Dim objSendMail
Dim strTo, strFrom
Dim strSubject, strBody

' Mail constants (some are for reference).
Const CdoBodyFormatHTML = 0 ' Body property is HTML
Const CdoBodyFormatText = 1 ' Body property is plain text (default)
Const CdoMailFormatMime = 0 ' NewMail object is in MIME format
Const CdoMailFormatText = 1 ' NewMail object is plain text (default)
Const CdoLow = 0 ' Low importance
Const CdoNormal = 1 ' Normal importance (default)
Const CdoHigh = 2 ' High importance

strFrom = "[email protected]" ' Change to your e-mail address.
strTo = "[email protected]" ' Change to the recipient address.
strSubject = "Test Message" ' Change to your subject.

' This line calls the ReadFile() function to read the page contents.
strBody = ReadFile("C:\MAILOUT.TXT")

' This line calls the MakePage() function to format the page as HTML.
strBody = MakePage(strSubject,strBody)

' The following section creates the mail object and sends the mail.
Set objSendMail = CreateObject("CDONTS.NewMail")
objSendMail.From = strFrom
objSendMail.To = strTo
objSendMail.Subject = strSubject & " (" & Date() & ")"
objSendMail.Body = strBody

objSendMail.BodyFormat = CdoBodyFormatHTML
objSendMail.MailFormat = CdoMailFormatMime
objSendMail.Importance = CdoNormal

Set objSendMail = Nothing

' This function returns a properly formatted HTML page.
Function MakePage(txtSubject, txtBody)
Dim txtTemp
txtTemp = "<HTML>" & vbCrLf
txtTemp = txtTemp & "<HEAD><TITLE>"
txtTemp = txtTemp & txtSubject
txtTemp = txtTemp & "</TITLE></HEAD>" & vbCrLf
txtTemp = txtTemp & "<BODY>" & vbCrLf
txtTemp = txtTemp & "<H2>" & txtSubject & "</H2>" & vbCrLf
txtTemp = txtTemp & txtBody & vbCrLf
txtTemp = txtTemp & "</BODY>" & vbCrLf
txtTemp = txtTemp & "</HTML>"
MakePage = txtTemp
End Function

' This function opens a file and returns the contents of the file.
Function ReadFile(txtFile)
Dim txtTemp, objFS, objFL
Set objFS = CreateObject("Scripting.FileSystemObject")
Set objFL = objFS.OpenTextFile(txtFile)
Do While Not objFL.AtEndOfStream
txtTemp = txtTemp & objFL.ReadLine
txtTemp = txtTemp & vbCrLf
Set objFS = Nothing
ReadFile = txtTemp
End Function

I have also placed the file mailout.txt which mailout.vbs is using at the correct place.

The code for mailout.txt is:
<p>This is line 1.</p>
<p>This is line 2.</p>

Thanks in advance for any help.

Reply With Quote
  #2 (permalink)  
Old February 2nd, 2005, 02:45 AM
vc1 vc1 is offline
Registered User
Join Date: Feb 2005
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts

Further to the above query.I checked and found that mail file is lying in the folder Inetpub->mailroot->Queue.

It is not going from Queue folder.Only when system is restarts the mails are send from the Queue.

Reply With Quote

Similar Threads
Thread Thread Starter Forum Replies Last Post
sending e-mails How To?? saudyonline General .NET 13 November 17th, 2006 01:00 AM
sending mails arabuafef Classic ASP Basics 0 July 18th, 2006 06:29 AM
Sending mails. rupen Javascript How-To 1 October 25th, 2005 07:22 AM
Sending e-mails using C# lily611 General .NET 3 June 30th, 2004 05:46 AM
Sending mails rajeshnerenki Pro VB 6 4 September 25th, 2003 03:34 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.