Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Other Programming > VBScript
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old February 2nd, 2005, 12:14 AM
vc1 vc1 is offline
Registered User
 
Join Date: Feb 2005
Location: , , .
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default Sending mails through vbs file

Hello,

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 = "hello123@gmail.com" ' Change to your e-mail address.
strTo = "hello123@yahoo.com" ' 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

objSendMail.Send
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
Loop
objFL.Close
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, 01:45 AM
vc1 vc1 is offline
Registered User
 
Join Date: Feb 2005
Location: , , .
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
sending e-mails How To?? saudyonline General .NET 13 November 17th, 2006 12: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



All times are GMT -4. The time now is 07:17 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.