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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Email Using CDONTS.NewMail 1

Status
Not open for further replies.

jmeckley

Programmer
Jul 15, 2002
5,269
US
I receive an error message when I attempt to send an email stating the server does not have CDONTS object.

What I am attempting to do is query the database, format the records and email the results as the body of the email.

While the email message object in DTS is nice, it does not allow me to dynamically create the message. The users do not want to recieve the text as an attachment.

What do I need to install on my computer to load the CDONTS object? OR is there another way to send dynamic email messages?

Jason Meckley
Database Analyst
WITF
 
I solved this problem, but I know have another issue.

First, to solve this issue I am using the CDO.Message object, instead of CDONTS.NewMail.

I have it setup and it executes without error, however nothing happens, I don't receive the email. any idea's why?

here is the code
Code:
Option Explicit
'**********************************************************************
'  Visual Basic ActiveX Script
'************************************************************************
Function Main()
	dim strEmailBody 
	dim objMail 
	dim objFeed

	const EXECUTIVE_EMAILS = "JMeckley <jmeckley@domain.com>" 
	const ADMIN = "Admin <admin@domain.com>" 

	set objMail = CreateObject("CDO.Message")
	set objFeed = DTSGlobalVariables("gFeed").Value

	While Not objFeed.EOF
		strEmailBody = objFeed.Fields(0).value & chr(13)
		objFeed.MoveNext 
	wEnd 

	With objMail
		.To = EXECUTIVE_EMAILS
		.From = ADMIN
		.Subject = "test" 
		.TextBody = strEmailBody
		.Configuration.Fields.Item("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/smtpserver")[/URL] ="[server name]"
		.Configuration.Fields.Update
		.Send
	End With

	If Err.Number = 0  Then
		Main = DTSTaskExecResult_Success
	Else
		Main = DTSTaskExecResult_Failure
		msgbox err.description
	End If
End Function

Jason Meckley
Database Analyst
WITF
 
You *can* set the Send Mail Task Message property dynamically in DTS.

1. Create a global variable to hold the message.

2. Using the ActiveX Script Task, set the value of the global variable to the message (e.g. DTSGlobalVariables("GlobalVariableName") = "This is the message."

3. Using the Dynamic Properties Task, set the Message Text property of the Send Mail Task to the global variable.


You can also dynamically set the address list, the subject, and other email properties this way.
 
The Message Text can also be set to the contents of an .INI or data file, or the results of a SQL query.
 
Thanks for the tip. the Dynamic properity task is very powerful.

Jason Meckley
Database Analyst
WITF
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top