Question : Automatic Email Sending

Hi guys!
I need some programming or program help... I want to know a script or a program that will automatically send an email to a specified address at the interval I set. Is there any script I can use in the background on my computer? Maybe something that I can give my email server settings to?

Thanks!

Answer : Automatic Email Sending

From virtually any version of Windows after say Windows 2000, you should be able to run a VBS via Windows Script Host.

You may need to install Windows Scripting Components: http://www.microsoft.com/downloads/details.aspx?FamilyID=C717D943-7E4B-4622-86EB-95A22B832CAA&displayLang=en (Windows up to Windows XP and Windows Server 2003)

or PowerShell http://technet.microsoft.com/en-us/scriptcenter/powershell.aspx (Windows XP or later, Windows Server 2008)

http://msdn.microsoft.com/en-us/library/9bbdkx3k%28VS.85%29.aspx discusses how to run a script, but if you have one of the above installed then running a vbs script simply means calling it like any program, which means from a scheduled task, batch file, or simply double clicking the vbs file.

Of specific concern in this case is having CDO.SYS installed which you need to send e-mail.

How to get: http://support.microsoft.com/kb/171440

So, while your simple script may suffice, it may need to be more complicated, at least slightly. But before that bridge is crossed you want to make sure you have scripting and Collaboration Data Objects installed correctly.

Both of which could be simple or complex depending on your environment and both could very well spawn questions of their own.

The reason your script may need to be more complex is that you are likely going to need to send the e-mail through one of your Exchange accounts and that will involve specifying the correct host or server and probably authentication.

So your little script will grow to something like the attached, which performs basic SMTP authentication against a remote server.  I packaged the dirty little details into a subroutine and added the CDO Type Library at the top so I can use CDO constants in the script. (Otherwise it grows quite a bit larger.)

The last line sendmail calls the subroutine and passes the from address, to address(es), subject and mail body.

Bigger or not it is still just a vbs script.

A test vbs script to see if WSH is installed could be a one liner,

msgbox("Hello World")

Regards,
Rod

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
<!--METADATA TYPE="typelib" UUID="CD000000-8B95-11D1-82DB-00C04FB1625D" name="CDO for Windows Library" -->

Sub sendmail(pFrom, pTo, pSubject, pBody)
    Dim objCDO
    Dim iConf
    Dim Flds

    Const cdoSendUsingPort = 2

    Set objCDO = Server.CreateObject("CDO.Message")
    Set iConf = Server.CreateObject("CDO.Configuration")

    Set Flds = iConf.Fields
    With Flds
        .Item(cdoSendUsingMethod) = cdoSendUsingPort
        .Item(cdoSMTPServer) = "smtp.example.com"
        .Item(cdoSMTPServerPort) = 25
        .Item(cdoSMTPconnectiontimeout) = 10
        ' Specify the type of authentication, NONE, Basic (Base64 encoded), NTLM
		.Item("smtpauthenticate") = cdoBasic
		.Item("sendusername") = "userid"
		.Item("sendpassword") = "password"
        .Update
    End With

    Set objCDO.Configuration = iConf

    objCDO.From = pFrom
    objCDO.To = pTo
    objCDO.Subject = pSubject
    objCDO.HTMLBody = pBody

    On Error Resume Next
    objCDO.Send
    If Err Then
        CDOMailIncludeResults="ERROR: "&err.number & " " & err.description & " " & err.source
    Else
        CDOMailIncludeResults="Sent"
    End If
    On Error Goto 0 

    Set ObjCDO = Nothing
    Set iConf = Nothing
    Set Flds = Nothing
End Sub

Dim fromAddress, toAddress, subject, body

fromAddress = "from@example.com"
toAddress = "to1@example.com; to2@example.com"
subject = "Reminder Message"
body = "Test Message - This could be HTML"

sendmail fromAddress, toAddress, subject, body
Random Solutions  
 
programming4us programming4us