Hi, I wrote a vb script in text file to send an automated email as a reminder to 36 recipients. I'm loading recipients from access database. I can send out email when i tried with test db, whereby there's only one recipient for each category (TO, CC, BCC). However, i got an error message :The server rejected one or more recipient addresses the server response was 501 5.5.4 invalid address.
Please help me anyone. My code is simply like below. Is it because of too many recipients? Where am doing wrong???

Sub SendMail(TheBody) 
    Dim objEmail
    Set objEmail = CreateObject("CDO.Message") 
    objEmail.Subject = "XXX"
    objEmail.From = "admin@xyz.com"          
    objEmail.To = getEmailAdd
    objEmail.CC = getEmailCC
    objEmail.BCC = getEmailBCC
    objEmail.Textbody = TheBody
    objEmail.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
    objEmail.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "XXX"
    objEmail.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
    objEmail.Configuration.Fields.Update
    objEmail.Send 
    End Sub 
                        
    Function getEmailAdd()
    SQLQuery = "SELECT emailAdd FROM tblEmail WHERE emailTo = -1" 
    Set Result = OBJdbConnection.Execute(SQLQuery) 
    Dim strEmailAdd
    if Not Result.EOF then 
    Do While Not Result.EOF 
    	strEmailAdd = strEmailAdd & Result("emailAdd") & "; "
      	Result.MoveNext 
    	Loop 
    end if 
    strEmailAdd = Left(strEmailAdd,Len(strEmailAdd)-2) 
    getEmailAdd = strEmailAdd
    End Function

Probably this is happening because the last addres is always a blank("; ".

To avoid this, I would suggest to do a simple change in the get function to be like:

Do While Not Result.EOF
        If (strEmailAdd.Length>0) Then strEmailAdd  = strEmailAdd & "; "
        strEmailAdd = strEmailAdd & Result("emailAdd")
        Result.MoveNext
    Loop

Hope this helps

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.