Binary Fortress Software

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: Email Plugin  (Read 7567 times)

guinness

  • Newbie
  • *
  • Offline Offline
  • Posts: 4
    • View Profile
Email Plugin
« on: August 09, 2007, 02:39:01 pm »

I've put together a simple plugin that will email the captured image after motion is detected.  It has a user defined inactivity period where captured images are ignored, to avoid flooding the SMTP server with images.

After Jon graciously provided the source code to the app, I modified his code to allow plugins.  I offered Jon that code so he can add it into his distribution, but if he decides against that, you can PM me and I will give you the modifications.

The code for the plugin is below, just place the file in the plugins folder (underneath folder containing the EXE) and compile with:
%SystemRoot%\Microsoft.NET\Framework\v2.0.50727\csc /target:library EmailImage.cs /r:..\\"Motion Monitor.exe"

EmailImage.cs
Code: [Select]
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Net.Mail;

public class EmailImage : MotionMonitor.IPlugin
{
    DateTime LastTime;

    public string AppName
    {
        get { return "Email Image Plugin"; }
    }

    public string AppDesc
    {
        get { return "This plugin sends captured image to SMTP server."; }
    }

    public string AppVer
    {
        get { return "1.0"; }
    }

    public void MotionDetected(string filename)
    {
        if (DateTime.Now > LastTime.AddMinutes(5))
        {
            SmtpClient smtp = new SmtpClient();
            smtp.Host = "localhost";
            smtp.Credentials = new NetworkCredential("user", "pass");

            MailMessage msg = new MailMessage("user@domain", "user@domain",
                "Motion Detected", "This picture was taken after motion was detected");
            msg.Attachments.Add(new Attachment(filename));
            smtp.Send(msg);

            LastTime = DateTime.Now;
        }
    }
}
« Last Edit: February 20, 2009, 09:31:48 am by Jon Tackabury »
Logged

Jon Tackabury

  • Administrator
  • Ultra Poster
  • *****
  • Offline Offline
  • Posts: 3768
    • View Profile
    • Binary Fortress Software
    • Email
Re: Email Plugin
« Reply #1 on: December 20, 2009, 01:44:58 pm »

I've added a link to this topic from the main Motion Monitor page. Thanks!
Logged
Lead Developer
Binary Fortress Software
http://www.binaryfortress.com