0

When a task is assigned to someone, the person that the task was previously assigned to is supposed to also be notified. However, this is not working. I am not sure why this email isn't being sent out to the .Cc email. Does anyone know how to fix this code? (The email IS being send to the msg.to recipient, and "testcc" does return the valid email address value.

Set msg=Server.CreateObject("CDONTS.NewMail")

strSQL = "select emailaddress from UserList where userid = "&assign&";"
Set rs = objConnection.Execute(strSQL, ,adCmdText)

if not(rs.BOF and rs.EOF) then
    temp = rs("emailaddress")
    if(temp<>"" and temp<>"NULL") then
        msg.To = rs("emailaddress")
    end if
end if

strSQL = "select emailaddress from UserList where username = '"&assignedTo&"';"
Set rs = objConnection.Execute(strSQL, ,adCmdText)
if not(rs.BOF and rs.EOF) then
msg.Cc = rs("emailaddress")
testcc = rs("emailaddress")
end if
Response.write(testcc)

msg.From = "support@test.com"
msg.Subject = relname & " TaskID: "&maintid&" - New Task Assignment"
msg.MailFormat = CdoMailFormatMime
msg.BodyFormat = CdoBodyFormatHTML
Enotes = ""
msg.Body = Body & Enotes
msg.Send()
J.J.
  • 1,128
  • 2
  • 23
  • 62
  • 2
    There's at least one `End If` missing from your code (at the end of the oddly-indented part). I don't know if that could be the root of your trouble, or if it's just an artifact of you trying to edit down the code to just the relevant parts. I do have one burning question: where did you ever unearth a server that still supports CDONTS? – Martha Jun 30 '15 at 00:07
  • Oh thanks, I just fixed that. That was a result of my previous editing. The server is a bit old honestly, haha. – J.J. Jun 30 '15 at 01:12
  • Why don't you format your code properly so that it's more readable? – Paul Jun 30 '15 at 08:39
  • 1
    Have you made sure that the data passed from the recordset is valid? Try appending an empty string to the start: `msg.Cc = "" & rs("emailaddress")` It is a dirty trick but it's used pretty widely and works well. – Paul Jun 30 '15 at 08:41

1 Answers1

2

1st of all: CDONTS was deprecated in Windows 2000 and removed completely in Windows 2003.

I suggest to use CDOSYS, which can be used from windows 2000 to windows 2008.

Code sample:

    On Error Resume Next
        Set myMail = Server.CreateObject("CDO.Message")
        myMail.BodyPart.charset = "unicode-1-1-utf-8"
        myMail.Subject  = EmailSubject
        myMail.HTMLBody = EmailBody
        myMail.From = EmailFrom
        myMail.To = EmailTO
        myMail.Cc = EmailCC
        myMail.BCc = EmailBCC

        myMail.Send
        Result = 2
    If Err.Number <> 0 Then
        Result = -1
    End If

    Set myMail = Nothing
Zam
  • 2,880
  • 1
  • 18
  • 33