sending mails in looop

Results 1 to 2 of 2

Thread: sending mails in looop

  1. #1
    Join Date
    Dec 1969

    Default sending mails in looop

    Hi friends,<BR><BR>From database I am fetching records and sending emails to users their UserIDs and passwords:<BR><BR>sql="Select distinct U.*,R.ROLE_ID,R.Role,C.REGION_NAME,ISNULL(CM.COUNT RY_NAME, &#039;NA&#039;) as cname from USER_MASTER U inner join ROLES R on U.ROLE_ID=R.ROLE_ID inner join Region_master C on U.Region_ID=C.Region_ID left outer join COUNTRY_MASTER CM on CM.COUNTRY_ID=U.COUNTRY_ID WHERE c.mask=0 AND U.MASK=0 and U.USER_ID IN(43,44,45,46) order by U.USER_NAME"<BR>set rs=ObjDBConn.execute(sql)<BR><BR><BR>Set objCDOMail = Server.CreateObject("Persits.MailSender")<BR>objCD OMail.Host = "" <BR><BR><BR><BR><BR>if not rs.eof then<BR> <BR> do until rs.eof<BR> <BR> shtml=shtml & "User Name:"&rs("USER_NAME")&"<BR>"<BR> SHTML=SHTML &"Password:"&rs("USER_pwd")&"<BR><BR>"<BR> <BR> <BR><BR> toid=rs("MAIL_ID")<BR> objCDOMail.From =""<BR><BR> objCDOMail.AddAddress ""<BR><BR> objCDOMail.Subject="Your user details- "&rs("USER_NAME")<BR> objCDOMail.Body = shtml<BR><BR> objCDOMail.IsHTML=1<BR> objCDOMail.Send<BR> &#039;response.write "Mail Sent successfully to -"&toid &"<BR>"<BR> on error resume next<BR> toid=""<BR> rs.movenext<BR> <BR> shtml=""<BR> Loop<BR> <BR> <BR> Set objCDOMail = Nothing<BR>end if <BR> <BR><BR><BR>There are 4 users in the db and it is sending 4 mails to each user with all others details also.. The problem is to mailid..<BR><BR>can anyone help me out with this <BR><BR>Regards

  2. #2
    Join Date
    Dec 1969

    Default The problem has to do...

    ...with your objCDOMail.AddAddress. As you go through the loop, you add another e-mail address as the recipient. The first time you go through the loop it&#039;s fine, but the second time round you send the e-mail to the first recipient as well as the second - and so on.<BR><BR>I don&#039;t know how your Persists.MailSender component works, but a workaround would be to destroy and re-create it every time you go through the loop - and not only once at the beginning and end.<BR><BR>However, there may be a ClearAddress method or something like that.<BR><BR>Oliver.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts