Monday, June 16, 2014

Java Event Trigger For Electronic Mail Notification(or Text Message)

On a recent project, a system which detected motion and then emailed and texted me the details was needed. In this post I will demonstrate how to do this using Processing and Dart:

In a previous post I demonstrated processing based motion tracking. Within the motion tracking file we will need to add:

open("C:\dartfile.dart");

which will open our Dart file once motion is detected. The dart code will utilize the mailer library :




import 'package:mailer/mailer.dart';


main() {
 
  var options = new GmailSmtpOptions()
    ..username = 'Username@.com'
    ..password = 'password';

  var emailTransport = new SmtpTransport(options);


  var envelope = new Envelope()
    ..from = 'Email'
    ..recipients.add('Email')
    ..subject = 'MOTION DETECTED!'
   
    ..text = ('MOTION DETECTED');
 

  //Email the text
  emailTransport.send(envelope)
    .then((success) => print('Members Alerted!'))
    .catchError((e) => print('Error occured: $e'));


}

We could also use the Dart code to alert us where the viewer is from(The dart code must be converted to JS before this is implemented:

<h1>
<script>
navigator.geolocation.getCurrentPosition(showPosition);

var x=position.coords.latitude;

var y=position.coords.longitude;

alert("Hujambo")
</script>


import 'package:mailer/mailer.dart';


main() {
 
  var options = new GmailSmtpOptions()
    ..username = 'Username@.com'
    ..password = 'password';

  var emailTransport = new SmtpTransport(options);


  var envelope = new Envelope()
    ..from = 'Email'
    ..recipients.add('Email')
    ..subject = 'MOTION DETECTED!'
   
    ..text = ('User Found at' + x +","+y);
 

  //Email the text
  emailTransport.send(envelope)
    .then((success) => print('Members Alerted!'))
    .catchError((e) => print('Error occured: $e'));

}

</h1>

Or we can track OS type:

alert(navigator.platform)

No comments:

Post a Comment