|
cliffdeen -> CDOSYS with Importance Flag (and multi emails) (2/25/2005 23:12:20)
|
Everyone - to help others in using Cdosys for emailing I thought it would be handy to post some code. It seems that documentation for certain aspects of Cdosys is spotty at best. Searching this forum I found a reference to setting the Importance flag for a email sent. However, one piece of code was not included in the thread so I am including it here. As a added bonus, I am also including a code example which allows you to send multiple emails based on a query from a db from a asp page. I hope this will save others the amount of time it took for me to track this down. While on the subject, kudos need to go to R. Douglass on this forum for helping me get the multiple email portion working. Quick explanation: Items in bold are items you will need to set for your dbserver/mail server. Dim Field "email" is the email address column in the db query and is used as the variable for the .To. The importance flag is set using the two lines prior to the .To. Note you need to use the Fields.Update function to get the importance flag to actually work. Importance # is 0 = Low 1= Normal and 2 = High. DO While not RS.EOF will cause the email send to loop until the query rows are exhausted. Finally - Cdosys on a asp page when executing does not display anything on the page. What I have done to give me a indication of a successful run is OUTSIDE the Code area - I place a <%=email%>. This will display the LAST send of the query when it has completed its' run. Note that code as shown is the only code on the page - no /html no /body - just the code.[:D] Code: <% Dim cn, RS, SQL, Conn, email, Z Dim objConfig ' As CDO.Configuration Dim objMessage ' As CDO.Message Dim Fields ' As ADODB.Fields Const cdoSendUsingMethod = "http://schemas.microsoft.com/cdo/configuration/sendusing" Const cdoSendUsingPort = 2 Const cdoSMTPServer = "http://schemas.microsoft.com/cdo/configuration/smtpserver" Const cdoSMTPServerPort = "http://schemas.microsoft.com/cdo/configuration/smtpserverport" Const cdoSMTPConnectionTimeout = "http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout" Const cdoSMTPAuthenticate = "http://schemas.microsoft.com/cdo/configuration/smtpauthenticate" Const cdoBasic = 1 Const cdoSendUserName = "http://schemas.microsoft.com/cdo/configuration/sendusername" Const cdoSendPassword = "http://schemas.microsoft.com/cdo/configuration/sendpassword" Set cn = Server.CreateObject("ADODB.Connection") cn.Open("Provider=SQLOLEDB;Server=CRPDALMSQ06;Database=ukdashSQL1;UID=IMU;pwd=hmfic2004;") 'This next line is your SQL for the data you want to use SQL = "Select * FROM emailtest" set Conn=server.createobject("adodb.connection") Conn.open cn Set RS = Conn.Execute (SQL) DO WHILE not RS.EOF email=(rs("email")) ' Get a handle on the config object and it's fields Set objConfig = Server.CreateObject("CDO.Configuration") Set Fields = objConfig.Fields ' Set config fields we care about With Fields .Item(cdoSendUsingMethod) = cdoSendUsingPort .Item(cdoSMTPServer) = "smtp3dns.my email server.com" .Item(cdoSMTPServerPort) = 25 .Item(cdoSMTPConnectionTimeout) = 10 .Item(cdoSMTPAuthenticate) = cdoBasic .Update End With Set objMessage = Server.CreateObject("CDO.Message") Set objMessage.Configuration = objConfig With objMessage .Fields("urn:schemas:httpmail:importance").Value = 2 .Fields.Update() .To = email .From = "emailtest@myemailserver.com" .Subject = "LET ME KNOW IF YOU GET THIS!" .textbody = "Testing importance flag. Hey this works:" .Send End With Set Fields = Nothing Set objMessage = Nothing Set objConfig = Nothing RS.MoveNext Loop Set RS = nothing Conn.close %>
|
|
|
|