Sending An Email


Recommended Posts

hi,

 

I need to arrange to send regular emails in my daq factory. But im not much familiar with these sequesnce. I followed the help files but dissicult to do it and if any one can send me a sample sequence  to send emails from the Daqfacory , then i can develope it to match my requirement.

 

So please post or send me a sample sequence for this.

 

Thanks in advance.

 

Best regards,

 

Thushara

Link to comment
Share on other sites

Sending an email is simply a matter of setting a bunch of variables correctly and doing email.send().  Something like this:

 

email.strHost = "smtp.myEmailServer.com"

email.port = 25

email.strAuthenticate = "AuthLogin"

email.strUserName = "me@mydomain.com"

email.strPassword = "mypassword"

email.strReplyAddress = "me@mydomain.com"

email.strReplyName = "Me"

//

email.strTo = "myFriend@somewhereElse.com"

email.strSubject = "How are you?"

email.strBody = "How have you been?  Where have you been?  See you later!  Me"

email.send()

 

Now usually you can set everything down to the // in a startup sequence and just leave it, then change the To, Subject, and Body for each email and hit send().  You do not need to reset those other variables each time if they are the same.  A few pointers:

 

1) you can only send emails one at a time.  You should typically leave maybe 15 seconds between trying to send multiple emails. 

2) the most common reason people have troubles with email is that they are trying to send the email through an smtp server that only accepts SSL connections (such as gmail).  DAQFactory cannot send emails over an SSL connection.

3) the next most common reason is they have the authentication settings wrong.

4) the next most common reason is they have the replyAddress set to something other than the login address.  Many servers will reject this because it looks like you are spamming.

Link to comment
Share on other sites

  • 2 weeks later...

hi Guru,

 

thanks a lot for your detail reply. i did according to you and now it works perfectly.

But here i need to send the values of some variables periodically. something like by 6 am every morning. So please let me know how to add the values of variables (like voltage, power) to the body of the email and also how to match the time with the real time clock (like 6 am).

 

Thanks in advance,

 

Thushara.

Link to comment
Share on other sites

Adding variables to the body is simply a matter of building up the string:

 

email.strBody = "Here is the latest value for myChannel: " + doubleToStr(myChannel[0])

 

As for doing something at 6am everyday, the easiest is to do this:

private nexttime = floor(systime() / 86400) * 86400 // gets us to midnight last night
nexttime += 3600*6  // gets us to 6am today
// check if its already after 6am today:
if (systime() > nexttime)
   nexttime += 86400
endif
while(1)
   waituntil(nexttime)
   // do whatever you want at 6am
   nexttime += 86400
endwhile
Link to comment
Share on other sites

Steve's burns a lot more CPU power (and also you need a second parameter for waitfor()...) since DAQFactory has to wake up at some interval and look at the time.  It has to do this with waituntil(), but that's much more efficient because DAQFactory can calculate how long it can go to sleep safely.  With waitfor() you have to specify the interval to wake up, and DAQFactory has to do the calculation every time.  Also, this technique doesn't work as well because significant changes in how long "stuff" takes can cause the delay to be too long and you miss the next one.

Link to comment
Share on other sites

How often does a waitfor() get evaluated and checked?  It's not like delay() or waituntil() where you can calculate in advance when it's going to complete and just ignore it till then.  Is it just dependent on the priority of the containing sequence?  Is there some kind of max or min interval?

Link to comment
Share on other sites

That's what the second parameter is for.  I'm pretty sure you can't just do:

 

waitfor(x == y)

 

you need to do:

 

waitfor(x==y, 1)

 

which will check every second.  Really, waitfor() is just shorthand for:

 

while(x != y)

   delay(1)

endwhile

 

waituntil() is totally different and like delay(), DAQFactory can sleep that thread for almost all that time, waking only occasionally and very briefly to check the time.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.