Alpha Software Mobile Development Tools:   Alpha Anywhere    |   Alpha TransForm subscribe to our YouTube Channel  Follow Us on LinkedIn  Follow Us on Twitter  Follow Us on Facebook

Announcement

Collapse

The Alpha Software Forum Participation Guidelines

The Alpha Software Forum is a free forum created for Alpha Software Developer Community to ask for help, exchange ideas, and share solutions. Alpha Software strives to create an environment where all members of the community can feel safe to participate. In order to ensure the Alpha Software Forum is a place where all feel welcome, forum participants are expected to behave as follows:
  • Be professional in your conduct
  • Be kind to others
  • Be constructive when giving feedback
  • Be open to new ideas and suggestions
  • Stay on topic


Be sure all comments and threads you post are respectful. Posts that contain any of the following content will be considered a violation of your agreement as a member of the Alpha Software Forum Community and will be moderated:
  • Spam.
  • Vulgar language.
  • Quotes from private conversations without permission, including pricing and other sales related discussions.
  • Personal attacks, insults, or subtle put-downs.
  • Harassment, bullying, threatening, mocking, shaming, or deriding anyone.
  • Sexist, racist, homophobic, transphobic, ableist, or otherwise discriminatory jokes and language.
  • Sexually explicit or violent material, links, or language.
  • Pirated, hacked, or copyright-infringing material.
  • Encouraging of others to engage in the above behaviors.


If a thread or post is found to contain any of the content outlined above, a moderator may choose to take one of the following actions:
  • Remove the Post or Thread - the content is removed from the forum.
  • Place the User in Moderation - all posts and new threads must be approved by a moderator before they are posted.
  • Temporarily Ban the User - user is banned from forum for a period of time.
  • Permanently Ban the User - user is permanently banned from the forum.


Moderators may also rename posts and threads if they are too generic or do not property reflect the content.

Moderators may move threads if they have been posted in the incorrect forum.

Threads/Posts questioning specific moderator decisions or actions (such as "why was a user banned?") are not allowed and will be removed.

The owners of Alpha Software Corporation (Forum Owner) reserve the right to remove, edit, move, or close any thread for any reason; or ban any forum member without notice, reason, or explanation.

Community members are encouraged to click the "Report Post" icon in the lower left of a given post if they feel the post is in violation of the rules. This will alert the Moderators to take a look.

Alpha Software Corporation may amend the guidelines from time to time and may also vary the procedures it sets out where appropriate in a particular case. Your agreement to comply with the guidelines will be deemed agreement to any changes to it.



Bonus TIPS for Successful Posting

Try a Search First
It is highly recommended that a Search be done on your topic before posting, as many questions have been answered in prior posts. As with any search engine, the shorter the search term, the more "hits" will be returned, but the more specific the search term is, the greater the relevance of those "hits". Searching for "table" might well return every message on the board while "tablesum" would greatly restrict the number of messages returned.

When you do post
First, make sure you are posting your question in the correct forum. For example, if you post an issue regarding Desktop applications on the Mobile & Browser Applications board , not only will your question not be seen by the appropriate audience, it may also be removed or relocated.

The more detail you provide about your problem or question, the more likely someone is to understand your request and be able to help. A sample database with a minimum of records (and its support files, zipped together) will make it much easier to diagnose issues with your application. Screen shots of error messages are especially helpful.

When explaining how to reproduce your problem, please be as detailed as possible. Describe every step, click-by-click and keypress-by-keypress. Otherwise when others try to duplicate your problem, they may do something slightly different and end up with different results.

A note about attachments
You may only attach one file to each message. Attachment file size is limited to 2MB. If you need to include several files, you may do so by zipping them into a single archive.

If you forgot to attach your files to your post, please do NOT create a new thread. Instead, reply to your original message and attach the file there.

When attaching screen shots, it is best to attach an image file (.BMP, .JPG, .GIF, .PNG, etc.) or a zip file of several images, as opposed to a Word document containing the screen shots. Because Word documents are prone to viruses, many message board users will not open your Word file, therefore limiting their ability to help you.

Similarly, if you are uploading a zipped archive, you should simply create a .ZIP file and not a self-extracting .EXE as many users will not run your EXE file.
See more
See less

Help with send email loop

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Help with send email loop

    I need help with some simple xbasic. I have a button on a form that was created using action scripting to send a report via email. It works as it should, but for only one record. I need it to loop thru the entire table (or all records that are within the query.filter)

    I would also like to put in the �pm.from_alias� if possible.

    Below is the code generated by action scripting:


    query.filter = "Current=\"Y\""
    query.order = "recno()"

    to_param = a5_eval_expression("=if(G1notify=\"Y\".and.G2notify=\"Y\",alltrim (G1email)+\",\"+alltrim(G2email),if(G1notify=\"N\".and.G2email=\"Y\",alltrim(G2email),if(G1notify=\"Y\".and.G2notify=\"N\",alltrim(G1email),\"\")))",local_variables())

    cc_param = a5_eval_expression("",local_variables())

    bcc_param = a5_eval_expression("",local_variables())

    subject_param = a5_eval_expression("Anson Golf Tournament Results",local_variables())

    message_param = a5_eval_expression("Open PDF to view tournament results",local_variables())


    :Report.Send("Results2-ColTwo","PDF",query.filter,query.order,"default",to_param,subject_param,message_param,cc_param,bcc_param)

    Thanks
    Tony

    #2
    Re: Help with send email loop

    I would also like to put in the �pm.from_alias� if possible.
    The from alias you mention is part of sending an email, not a report.

    I need it to loop thru the entire table (or all records that are within the query.filter
    What table? (name)
    There can be only one.

    Comment


      #3
      Re: Help with send email loop

      Stan
      The table name is "tourney"
      Thanks for the quick response!
      Tony

      Comment


        #4
        Re: Help with send email loop

        HI!

        There are many ways to do this and I'm sure Stan will give your several, but what I found good to use was Netmailer. It is an Alpah5 addd-on and helps you to automate mailings like this. You can select the records you want to use, save it all in a config file and then call it up within xbasic.

        Just a thought...

        Charlie

        Comment


          #5
          Re: Help with send email loop

          Sorry, got distracted. Assuming the G1notify, G2notify, G1email, G2email are fields in the tourney table.......

          If you want to have the button on a form based on the tourney table use option 1. If the button is on a "menu" dummy table, option 2.

          Code:
          tbl = table.current() ' [COLOR="Blue"]option 1[/COLOR]
          'tbl = table.open("tourney") ' [COLOR="blue"]option 2, comment out first line and uncomment this (and last line) for option 2[/COLOR]
          query.filter = "Current=\"Y\""
          query.order = "recno()"
          query.description = "Temporary Query"
          query.options = "I"
          ix = tbl.query_create()
          recs = ix.records_get()
          if recs = 0
          	end
          end if
          tbl.fetch_first()
          while .not. tbl.fetch_eof()
          
          to_param = if(tbl.G1notify="Y" .and. tbl.G2notify="Y",alltrim (tbl.G1email)+","+alltrim(tbl.G2email),if(tbl.G1notify="N".and.tbl.G2email="Y",alltrim(tbl.G2email),if(tbl.G1notify="Y".and.tbl.G2notify="N",alltrim(tbl.G1email),"")))
          cc_param = ""
          bcc_param = ""
          subject_param = "Anson Golf Tournament Results"
          message_param = "Open PDF to view tournament results"
          
          :Report.Send("Results2-ColTwo","PDF",query.filter,query.order,"default",to_param,subject_param,message_param,cc_param,bcc_param)
          tbl.fetch_next()
          end while
          'tbl.close [COLOR="Blue"]'only with option 2[/COLOR]
          There can be only one.

          Comment


            #6
            Re: Help with send email loop

            Stan
            Thanks, I will have time tonight to give this a try and post the results.
            Tony

            Comment


              #7
              Re: Help with send email loop

              Stan

              I used "option 1" and it worked, however, a separate email was brought up for each record (one or two email addresses) that was within the query (could be up to 50 separate emails).

              I had hoped that one email could be sent for 1 or 50 golfers that wanted to be notified.

              Is that possible?

              Thanks for your help,
              Tony

              Comment


                #8
                Re: Help with send email loop

                It is possible. I'll get back to you tomorrow.
                There can be only one.

                Comment


                  #9
                  Re: Help with send email loop

                  I used a "report.save_as", then attached the report to the e-mails using the e-mail_send command. This sends them in "batch" without you having to click on each one to end it. see attached.

                  Code:
                  tblC = table.open("clients")
                  text1 = get_from_file("C:\FORECAST\timing.txt")
                  a1.initialize(text1)
                  N = val(a1[1]) 'N is the number of e-mails to do in a batch
                  L = val(a1[2]) 'L is the number of seconds to wait after each e-mail
                  M = val(a1[3]) 'M is the number of seconds to wait between batches
                  Skip = val(a1[4]) 'SKIP is the number of e-mails that had been sent in a previous attempt.
                  
                  tblC.index_primary_put("Location")
                  tblC.fetch_first()
                  dim I as N
                  dim K as N
                  J=0
                  K=0
                  I=0
                  h = 0
                  while .not.tblC.fetch_eof()
                  	if tblC.Email_addr = "" .or. marked("clients")
                  		tblC.fetch_next()
                  	  else
                  		if Skip >0
                  			while h < Skip
                  				tblC.fetch_next()
                  				h = h+1
                  			end while
                  		end if
                  		if I < N 
                  			J=J+1
                  			I=I+1
                  		if tblC.Report_Hdr <>""
                  			loc1 = tblC.Report_Hdr
                  		  else
                  	 	 	loc1 = tblC.location
                  		end if	
                  
                  [COLOR="Red"]			pdf_filename = "C:\Forecast\reports"+chr(92)+trim(loc1)+"_Pavement_forecast.pdf"
                  [/COLOR]			msg_text = "Attached is the Pavement Condition Forecast for "+strtran(loc1,"_"," ")
                  			param_to = trim(tblC.Email_addr)
                  			param_subject = alltrim(strtran(loc1,"_"," "))+" Pavement Condition Forecast"
                  			param_cc = ""
                  			param_bcc = ""
                  			param_msg = msg_text
                  			[COLOR="Red"]param_attachments = pdf_filename[/COLOR]
                                          email_Send(param_to,param_subject,param_msg,param_attachments)
                  			tblC.fetch_next()
                  			sleep(L)
                  		  else
                  	  		sleep(M)
                  			I=0
                  			K=K+N
                  			'tbl1.fetch_next()
                  		end if
                  	end if
                  end while
                  Just remember, when doing batch e-mails, your ISP may think you're spamming, so they will shut down the outgoing port. That is why I put the timing delays in.

                  Tom

                  Comment


                    #10
                    Re: Help with send email loop

                    Tom

                    Thanks for the response. I may give it a try later today or tomorrow, but I am so limited in my knowledge of XBasic that I'm not sure I can substitute my information into your example and make it work.

                    I am holding out hope that Stan can advise later today on how to make his example work.

                    Thanks to each of you and to all the many people that take the time to give advice and help to those of us that are a little "XBasic Challenged"

                    Thanks
                    Tony

                    Comment


                      #11
                      Re: Help with send email loop

                      Was waiting to see if you wanted to give that a go. This should work if the email client supports as many send to's as you have.

                      Code:
                      tbl = table.current() ' option 1
                      query.filter = "Current=\"Y\""
                      query.order = "recno()"
                      query.description = "Temporary Query"
                      query.options = "I"
                      ix = tbl.query_create()
                      recs = ix.records_get()
                      if recs = 0
                      	end
                      end if
                      tbl.fetch_first()
                      'initialize variable for accumulation each to_param value
                      send_to_list = ""
                      while .not. tbl.fetch_eof()
                      to_param = if(tbl.G1notify="Y" .and. tbl.G2notify="Y",alltrim (tbl.G1email)+","+alltrim(tbl.G2email),if(tbl.G1notify="N".and.tbl.G2email="Y",alltrim(tbl.G2email),if(tbl.G1notify="Y".and.tbl.G2notify="N",alltrim(tbl.G1email),"")))
                      send_to_list = send_to_list+to_param+","
                      tbl.fetch_next()
                      end while
                      cc_param = ""
                      bcc_param = ""
                      subject_param = "Anson Golf Tournament Results"
                      message_param = "Open PDF to view tournament results"
                      'remove initial comma
                      send_to_list = substr(send_to_list,2)
                      :Report.Send("Results2-ColTwo","PDF",query.filter,query.order,"default",send_to_list,subject_param,message_param,cc_param,bcc_param)
                      There can be only one.

                      Comment


                        #12
                        Re: Help with send email loop

                        try this:

                        Code:
                        tblC = table.open("tourney")
                        
                        N = 20 'N is the number of e-mails to do in a batch
                        L = 5 'L is the number of seconds to wait after each e-mail
                        M = 60 'M is the number of seconds to wait between batches
                        Skip = 0 'SKIP is the number of e-mails that had been sent in a previous attempt.
                        param_to = ""
                        query.filter = "current = \"Y\""
                        query.order = ""
                        ix = tblc.query_create()
                        I = 1
                        tblC.fetch_first()
                        while .not.tblC.fetch_eof()
                        	if I < N
                        		param_to = ""
                        		if G1notify = "Y"
                        			param_to = alltrim(g1email)
                        		end if
                        		if g2notify = "Y"
                        			if param_to <> ""
                        				param_to = param_to +","+alltrim(g2email)
                        	  		  else
                        				param_to = alltrim(g2email)
                        			end if
                        		end if			
                        		pdf_filename = "YOUR SAVED PDF FILE"   <<<<<=================  
                        		msg_text = "Open the attached PDF to view tournament results"
                        		param_subject = "Anson Golf Tournament Results"
                        		param_msg = msg_text
                        		param_attachments = pdf_filename
                        	        email_Send(param_to,param_subject,param_msg,param_attachments)
                        		tblC.fetch_next()
                        		I = I+1
                        		sleep(L)
                        	  else
                        	  	sleep(M)
                        		I=0
                        		'tbl1.fetch_next()
                        		end if
                        	end if
                        end while

                        Comment


                          #13
                          Re: Help with send email loop

                          Stan
                          I tried your example and could not send any emails.
                          A error message was returned:

                          "MAPI ERROR - One or more recipients were invalid or did not resolve to any address. (MAPI_E_INVALID_RECIPS)

                          Just so you'll know, I have things set for the purpose of simplicity, that two golfers from one record and one golfer, from another record are set to receive emails. (so three total at this time)

                          Thanks
                          Tony

                          Comment


                            #14
                            Re: Help with send email loop

                            Tom

                            Thanks for inserting my information. I will give it a try!

                            Thanks
                            Tony

                            Comment


                              #15
                              Re: Help with send email loop

                              Tony,
                              Just remember, you need to create the PDF file with a report.saveas(). check the help file for all the formatting parameters. this is what I'm using in a loop to create specific reports for specific clients.

                              Code:
                              		pdf_filename = "C:\Forecast\reports"+chr(92)+trim(loc1)+"_Pavement_forecast.pdf"
                              		if file_exists(pdf_filename)
                              			file_remove(pdf_filename)
                              		end if
                              		filt1 = "location="+quote(trim(tbl2.Location))
                              		query.filter = filt1
                              		query.order = ""
                              		[COLOR="Red"]report.SaveAs("Conditions Letters",[COLOR="Navy"]"PDF"[/COLOR],query.filter,query.order,pdf_filename)[/COLOR]
                              as far as the mapi errors, check the e-mail addresses for accuracy.

                              Tom

                              Comment

                              Working...
                              X