0

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
2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by lolafuertes
0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.