PDA

View Full Version : auto mail (W2K)



mcslemon
04-07-2003, 01:51 AM
Why is this code looping??

I double click on the script and suddenly my HDD light stays on for ages and I get loads of mails!! Can anyone see anything wrong with it?

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 = "an@emai" ' Change to your e-mail address.
strTo = "an@email" ' Change to the recipient address.
strSubject = "CATS Error" ' 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

Cheers,
Neil.

mcslemon
04-07-2003, 05:22 AM
I've also used this one and it also sends IIS/SMTP into a loop and sends loads of emails. I don't think its the code, more a setting....any ideas?

set mailmsg = createobject("CDONTS.newmail")
mailmsg.from ="<email address>"
mailmsg.TO = "<email address>"
mailmsg.Importance = 1
mailmsg.body = "Body text with now function at end" & Now()
mailmsg.Subject = "Subject Line"
'mailmsg.AttachFile currentfile 'File Path c:\myfile.txt
mailmsg.send
set mailmsg = nothing

mcslemon
04-08-2003, 04:44 AM
heheh replying to myself alot aren't i!

Ok, I think I've got it.

It seems to be IIS/SMTP.

When the script sends an email, it puts it into the pickup folder in inetpub/mailroot, and then the smtp sends it, but keeps sending it until you delete it from the pickup folder. I've set up a function in the wsh script which deletes it from the pickup script after 0.175 seconds so it has a chance to send!! Bit of a hack!

Why is is sitting in the Pickup folder? Is it something I should know about in the fuctionality of virtual smtp server?

sentme_mail
04-10-2003, 09:25 AM
how can i automate sending of mails if i have outlook client installed?

mcslemon
05-22-2003, 02:03 AM
ok, for anyone interested....its was because you need to give system and everyone users full rights to these 2 dirs to stop it looping....they could add something to the folder, but not delete it!