Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sending e-mail thru vbs 2

Status
Not open for further replies.

EdRev

Programmer
Aug 29, 2000
510
US
I went MS site and go this sample code:

dim objEmail
Set objEmail = CreateObject("CDO.Message")
objEmail.From = "email@aol.com"
objEmail.To = "email@aol.com"
objEmail.Subject = "Atl-dc-01 down"
objEmail.Textbody = "Atl-dc-01 is no longer accessible over the network."
objEmail.Send

I got an error - "ActiveX component can't create object: 'CDO.Meassage'"

Do I need to install anything for this to work?


 
No expert here. However, first question is what is your OS?

If you are using WinNT 4 svrpack x you can only use CDONTS.

If you are using Win2000 or > you should be able to use CDO.

To find out if it is on your system, do a search for: cdo*.dll

CDONTS.DLL
CDOSYS.DLL

From what I have found, you can effectively use either on a Win2000 system, assuming it is installed. Obviously, you can only use CDONTS on the WinNT system.

I have two Win2000 systems on my desk. One does NOT have either CDONTS or CDOSYS on it. The other does. Why, I do not know. May be an option I failed to select when I installed both PC's.

BTW the syntax for using them are similar but there are differences. Search this site or GOOGLE. Took me a while to stumble onto a site. Vaguely remember using "cdo and objects" or some combination there of.

Hope it helps.

Doug Cranston
 
EdRev:

Here's a piece of code I use for a sys admin task. The PC must have Outlook on it for it to work. I hope this helps.

mapman04

'================= E-mail Automation ==================================
'======================================================================
' Sends an e-mail to the recipient.

dim oSession, oMessage, oAttachment, oRecipient, strSubject, strText, strFname, strLoc
dim sTo, Name1, Name2

Name1 = "SMTP:user@anycompany.com"
sTo= Name1
strSubject = "Reset of Files"
strText = "The reset process was successful!" & vbCr & vbCr & _
"This messages was generated by a vbScript at: " & Now() & vbCr & vbCr & "SysAdmin"

set oSession=CreateObject("MAPI.Session")
oSession.Logon "User"
set oMessage=oSession.Outbox.Messages.Add(strSubject,strText)
set oRecipient=oMessage.Recipients.Add(,sTo)
oRecipient.Resolve
oMessage.Send
oSession.Logoff
set oSession=nothing

WScript.Quit
 
Thanks guys.

tried the MS code on windows 2000 and it didn't give me that original error message about ActiveX Component....
but got another error message...The transport failed to connect to the server....Any ideas?

 
For what it is worth, attached is the code I recently adapted/created for one of my scripts that creates an Excel file based on an Access DB. This is in the process of automating some of my tasks. Have two servers. One is NT the other is Win2000, and ultimately only Win2000. Just haven't had the time to convert. I do not have Outlook installed. Using an SMTP server on our network for the outbound traffic.

Doug Cranston


Public Function sndfilemsg(argsvalue)
' Emails the report to the assigned personnel
' Set Error Handler
On Error Resume Next

argtst = cint(argsvalue)

If argtst = 0 then
' Send Error Message to System Administrators of Problem Encountered
' If used on WIN2 Server/WS remove the double ''
' and then comment out the CDONTS

' Sending a text email using a CDOSYS not CDONTS

Set oMessage = CreateObject("CDO.Message")

oMessage.From = "youremail@somewhere.com"
oMessage.To = "youremail@somewhere.com"
oMessage.Subject = "Report Requests: "
oMessage.AddAttachment "c:\cmdfiles\tempfile\outit.xls"
oMessage.TextBody = "The attached Excel file contains last months Requests Summary." & VbCrLf
oMessage.Configuration.Fields.Item _
(" = 2
oMessage.Configuration.Fields.Item _
(" = _
"smtp.tel.gte.com"
oMessage.Configuration.Fields.Item _
(" = 25
oMessage.Configuration.Fields.Update
oMessage.Send
Set oMessage=Nothing

' CDONTS email for NT
' If using CDONTS remove double single quotes and comment out CDOSYS lines

'' set oMessage = CreateObject("CDONTS.NewMail")
'' oMessage.Subject = "Report Requests"
'' oMessage.From = "youremail@somewhere.com"
'' oMessage.To = "youremail@somewhere.com"
'' oMessage.Cc = "youremail@somewhere.com"
'' oMessage.AttachFile("c:\cmdfiles\tempfile\outit.xls")
'' oMessage.Body = "The attached Excel file contains last months Requests Summary." & VbCrLf
'' oMessage.Send
'' set oMessage=nothing

End if

'Test for Error
If Err.Number <> 0 then
strErrCd = &quot;Creating Email distribution process failed.&quot;
call LogErrors(Err, strErrCd)
wscript.quit(1)
End if

End Function
 
I use this one to send email with an attachment
using outlook. Enjoy Bob.

Dim ToAddress
Dim FromAddress
Dim MessageSubject
Dim MessageBody
Dim MessageAttachment
Dim ol, ns, newMail
ToAddress = &quot;somename@email.com&quot;
MessageSubject = &quot;Reader Service Leads&quot;
MessageBody = &quot;Here are your leads for 02-19-2003&quot;
MessageAttachment = &quot;Y:\folder\folder\10196.csv&quot;
Set ol = WScript.CreateObject(&quot;Outlook.Application&quot;)
Set ns = ol.getNamespace(&quot;MAPI&quot;)
Set newMail = ol.CreateItem(olMailItem)
newMail.Subject = MessageSubject
newMail.Body = MessageBody & vbCrLf
newMail.RecipIents.Add(ToAddress)
newMail.Attachments.Add(MessageAttachment)
newMail.Send
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top