Patch for SMTP with SSL

If you've made a patch to quick fix a bug or to add a new feature not yet in the main tree then post it here so others can try it out.
nausser
Posts: 18
Joined: Sat Oct 09, 2010 9:08 pm
Location: South Florida

Post by nausser »

Try this script to test your perl email function. I received this very helpfuil script from the ever helpful mateuszknapik. I can send email messages from the command line with this script he gave me, however, I still have not gotten Zoneminder to send the emails. But at least I know its not perl that is the problem. Give it a shot and see for yourself.

Code: Select all

#!/usr/bin/perl -w

require Net::SMTP::SSL;
require MIME::Lite;

my $to = 'send_to_email@gmail.com';
my $from = 'sent_from_email@gmail.com';# Also works with Google Apps domains
my $password = 'gmail_password';

sub send_mail {
my $to = $_[0];
my $subject = $_[1];
my $body = $_[2];

my $smtp_port=465;

my $mail = MIME::Lite->new (
	From => $from,
	To => $to,
	Subject => $subject,
	Type => "multipart/mixed"
);

die "Problem with $mail" unless $mail;

$mail->attach (
	Type => "TEXT",
	Data => $body
);

$mail->attach (
	Path => "test.pl",
	Type => "application/x-perl",
	Disposition => "attachment"
);

my $smtp = Net::SMTP::SSL->new('smtp.gmail.com', Port => 465, Debug => 
1);

$smtp->auth($from, $password) || die "Authentication failed!\n";



$smtp->mail($from . "\n");
my @recepients = split(/,/, $to);
foreach my $recp (@recepients) {
    $smtp->to($recp . "\n");
}
$smtp->data($mail->as_string);
$smtp->quit;
}

# Send away!
&send_mail($to, 'Test successful', 'Some more detail');
Save this script anywhere on your machine(home folder works fine) as 'test.pl'. Make it executable by:

Code: Select all

sudo chmod a+x test.pl
Run the script and send yourself an email by:

Code: Select all

sudo ./test.pl
Personally, I've gone over the modded /usr/bin/zmfilter.pl so many times I know it by heart. I can't figure this one out. This script works wonderfully, however, the zmfilter.pl is not utilizing the perl email functions like this simple script is. If you have more luck applying the success of this test script to your ZoneMinder config, please fill me in as soon as you can!
I hope this helps narrow down your issue.
Time never ceases to accelerate.
lewsut
Posts: 10
Joined: Sun Jan 02, 2011 12:46 am

Post by lewsut »

Thanks for that, the test works like a charm!

I have downloaded the zmfilter.pl replacement made the appropriate changes to mysql and edited ConfigAdmin.pm to advised. Still I get no emails.

I see that in my zmdc log I have an error: 'zmfilter.pl ' exited abnormally, exit status 9, that does not look very good.

Thanks for your help :D
nausser
Posts: 18
Joined: Sat Oct 09, 2010 9:08 pm
Location: South Florida

<SOLVED> Ubuntu gmail SSL mod

Post by nausser »

Okay. I seem to have it all working finally so here is a recap on all the files and configs that I'm using.

First off, the system ZoneMinder is installed on is a multi-function system. I only have one webcam to watch the dog and be alerted when people are in the house. I am also running MythTV at full HD front and backend as well as Boxee.
I'm currently upgraded to Ubuntu 10.04.1 32bit. I am not running a local mail server of any kind. I go through gmail directly for all my email sending needs. Also, my address isn't a "@gmail.com" address. It is my own domain that I have Google Apps tied into to handle all my domain's email.

I basically did everything listed on the first page of this thread. I'm not exactly sure why it wouldn't work before and works now but I have been tinkering with scripts as well as ZoneMinder's filter settings and am now in good shape.

I want to give a HUGE thank you to the author of this thread, mateuszknapik. He has more than gone out of his way to help me through this issue of gmail SSL not working in Ubuntu.

I will first post my /usr/bin/zmfilter.pl file so you know my end result that I am now working with.

http://nerdsonstandby.com/zmfilter

My SQL database was updated via SSH as I never installed PHPMyAdmin or any other mySQL GUI. I terminaled directly into the database to edit ZoneMinder's DB config. I used to following to login. You'll need your ZoneMinder DB username and password. Enter into your database like this. (Change 'zmusername' to your mySQL username, zmpassword to your mySQL password and replace zm at the end with the database name ZoneMinder uses in your configuration. You can get all this information at the end of the file: '/etc/zm/zm.conf'.)

Code: Select all

mysql --user=zmusername --password=zmpassword zm
Now you are at the mysql prompt where you can paste in the database additions/corrections mateuszknapik posted.

Code: Select all

INSERT INTO `Config` (`Id`, `Name`, `Value`, `Type`, `DefaultValue`, `Hint`, `Pattern`, `Format`, `Prompt`, `Help`, `Category`, `Readonly`, `Requires`) VALUES
(183, 'ZM_SMTP_SSL', '0', 'boolean', 'yes', 'yes|no', '(?i-xsm:^([yn]))', '($1 =~ /^y/) ? "yes" : "no" ', 'Whether to use SMTP with authorization and SSL or not', NULL, 'mail', 0, 'ZM_NEW_MAIL_MODULES=1'),
(184, 'ZM_SMTP_PORT', '465', 'integer', '465', NULL, '(?-xism:^(d+)$)', '$1', 'SMTP port', NULL, 'mail', 0, 'ZM_SMTP_SSL=1\r\nZM_NEW_MAIL_MODULES=1'),
(185, 'ZM_SMTP_PASSWORD', 'your_smtp_password', 'string', NULL, 'string', '(?-xism:^(.+)$)', '$1', 'Your SMTP auth password', NULL, 'mail', 0, 'ZM_SMTP_SSL=1\r\nZM_NEW_MAIL_MODULES=1');
Now make the ConfigAdmin.pm additions. The location of this file is '/usr/share/perl5/ZoneMinder/ConfigAdmin.pm'. Use your favorite editor again and the end result should be this. I've added the previous entry and what follows so you'll know exactly where it goes. Just look at Normando's post for clarification if you need more info.
Above:

Code: Select all

{
		name => "ZM_DYN_SHOW_DONATE_REMINDER",
		default => "yes",
		description => "Remind about donations or not",
		help => "",
		type => $types{boolean},
		readonly => 1,
		category => "dynamic",
	},
Added lines:

Code: Select all

{ 
                name => "ZM_SMTP_SSL", 
                default => "yes", 
                description => "Whether to use SMTP with authorization and SSL or not", 
                help => "", 
                type => $types{boolean}, 
                readonly => 0, 
                requires => [ { name=>"ZM_NEW_MAIL_MODULES", value=>"1" } ], 
                category => "mail", 
        }, 
        { 
                name => "ZM_SMTP_PORT", 
                default => "465", 
                description => "SMTP port", 
                help => "", 
                type => $types{integer}, 
                readonly => 0, 
                requires => [ { name=>"ZM_SMTP_SSL", value=>"1" }, { name=>"ZM_NEW_MAIL_MODULES", value=>"1" } ], 
                category => "mail", 
        }, 
        { 
                name => "ZM_SMTP_PASSWORD", 
                default => "", 
                description => "Your SMTP auth password", 
                help => "", 
                type => $types{string}, 
                readonly => 0, 
                requires => [ { name=>"ZM_SMTP_SSL", value=>"1" }, { name=>"ZM_NEW_MAIL_MODULES", value=>"1" } ], 
                category => "mail", 
        },
Below:

Code: Select all

);

our %options_hash = map { ( $_->{name}, $_ ) } @options;

sub INIT
Now we need to make sure perl is good to go for sending emails. Make sure you have all the dependencies. I didn't have them all for some reason. Thanks again to mateuszknapik for supplying:

Code: Select all

sudo apt-get install libnet-smtp-ssl-perl libio-socket-ssl-perl libnet-ssleay-perl libauthen-sasl-perl
EDIT: The below cpan part I did not do on the newest ZM ubuntu box I built. I am able to complete the test.pl script noted above in a previous post without installing cpan and hence, then doing 'install Net::SMTP::SSL'. Save yourself the extra step!
Next thing is to install cpan. I don't know for a fact that this was necessary but I did do it and it is now working so I'll add it in this list of things to do.

Code: Select all

sudo cpan 
>> install Net::SMTP::SSL 
[blablabla] 
>> quit
The above will take you through seemingly endless prompts to configure. The majority of the prompts had defaults to simply accept by hitting enter.
There is a test script to use that I posted (also from mateuszknapik of course). Give it a try now and make sure the email portion works.
from there I configured the ZoneMinder Email tab in the options panel just as illustrated in the first post of this thread.
http://img208.imageshack.us/img208/7299 ... 004xb7.jpg
The only thing I didn't do was check the 'ZM_OPT_MESSAGE' option as I don't care to text my phone. Email on a smart phone is rather common now days. You can find other ZoneMinder info to add in your emails if you'd like at the ZM wiki:
http://www.zoneminder.com/wiki/index.ph ... ing_Events
For a email filter, I just used alarm frames. I may adjust the amount of frames to match depending on how many emails I end up getting. I made the filter settings as illustrated, saved, gave it a name and checked to run in the background.
Image
I also changed another setting so I would get the email quicker while the alarm frames were being triggered. (I don't doubt there is a better way but it does shave off some time from when the alarm is triggered and when the email with the picture comes in. The change is in the ZoneMinder options screen under the Config tab. The listing is 'EVENT_CLOSE_MODE'. I changed it from idle to alarm.

That does it though. I now have my email updates through gmail SSL working flawlessly on an Ubuntu installation.
Last edited by nausser on Tue Jan 11, 2011 10:24 pm, edited 3 times in total.
Time never ceases to accelerate.
lewsut
Posts: 10
Joined: Sun Jan 02, 2011 12:46 am

Post by lewsut »

Thanks for this !

I had a quick run trough but seem to be getting the same result as before 'zmfilter.pl ' exited abnormally, exit status 9. Am I making a rediculous school boy error in the fact that I am just editing the file (via webmin or nano) and saving changes?

Cheers for all your work I'll keep trying, it has all been very useful.
mateuszknapik
Posts: 6
Joined: Tue May 20, 2008 10:30 am
Location: Poland

Post by mateuszknapik »

Hi everyone!
Sorry for my absence, but I was busy. I'm glad that nausser's system is working properly and I hope his post will help solve all problems :)
@lewsut, did you try this? http://www.zoneminder.com/forums/viewtopic.php?p=58411
lewsut
Posts: 10
Joined: Sun Jan 02, 2011 12:46 am

Post by lewsut »

Cheers for the reply, yes earlier I had indeed tried that.

I think I'm just being an idiot as when I run nausser's modified zmfilter.pl (as per above) on its own I get a million errors (such as below), as a complete novice to anything Linux I'm not sure if I can just run it to troubleshoot.

Global symbol "@filters" requires explicit package name at ./zmfilter.pl line 519.
Unmatched right curly bracket at ./zmfilter.pl line 520, at end of line
./zmfilter.pl has too many errors.


Will keep trying.

Cheers.

UPDATE: I got it working by removing @EXTRA_PERL_LIB@ from mateuszknapik's zmfilter.pl file (it was the first line that had an error when I tried to run it on its own) :D Not exactly sure what that does, but with it I get errors with it and without it, it works.

Thanks all !
nausser
Posts: 18
Joined: Sat Oct 09, 2010 9:08 pm
Location: South Florida

Post by nausser »

Glad to hear you're up and running as well!
Time never ceases to accelerate.
DVIELIS
Posts: 2
Joined: Wed Jan 05, 2011 9:25 am
Location: Europe - Latvia

Post by DVIELIS »

Hello .. I have the same problem as been nausser ....

I have Ubuntu 10.10 desktop ....
Zone Minder 1.24.2 ....

I change manually zmfilter.pl file ....
Then i follow the nausser last instructions
nausser wrote:Okay. I seem to have it all working finally so here is a recap on all the files and configs that I'm using.

First off, the system ZoneMinder is installed on is a multi-function system......

............................

Code: Select all

#!/usr/bin/perl -wT
#


# ==========================================================================
#
# ZoneMinder Event Filter Script, $Date: 2009-06-08 10:11:56 +0100 (Mon, 08 Jun 2009) $, $Revision: 2908 $
# Copyright (C) 2001-2008 Philip Coombes

....................

I open a 25 port and 465 port on my rooter end try the nausser test script to send e-mail .. works wonderful ...

But don`t work ZoneMinder mail sender..

In log File (zmfilter.log in /tmp) i got the same text as nausser with other parameters. (Now i not at my Ubuntu PC, because i can`t post my log)

Code: Select all

12/29/10 11:26:43.804231 zmfilter[2643].INF [Creating notification email]
12/29/10 11:26:43.804453 zmfilter[2643].INF [Sending notification email 'ZoneMinder: Alarm - Logitech-221334 (31 - 22 4)'] 
But i think the log must be something like that

Code: Select all

09/16/08 19:40:26.301834 zmfilter[9054].INF [Creating notification email]
09/16/08 19:40:26.304988 zmfilter[9054].INF [Sending notification email 'ZoneMinder: Alarm - path-328 (6 - 5 13)']
09/16/08 19:40:26.350486 zmfilter[9054].INF [Attaching '/usr/share/zoneminder/events/5/08/09/16/19/34/00/011-capture.jpg]
09/16/08 19:40:29.775646 zmfilter[9054].INF [Notification email sent] 
When i go home, i try replase all zmfilter.pl ...
now i work with manually changed file contain ....

Sorry for my bad english .. :shock: :lol: :D

Ideas...?

:roll:
nausser
Posts: 18
Joined: Sat Oct 09, 2010 9:08 pm
Location: South Florida

Post by nausser »

I'm going to try this full config on another ZM machine I'm building. I'm still waiting for a capture card to arrive from the UK though. I'll post my findings to duplicate what I ended up using on this new machine.

Right now I unfortuneately can't be much help. I posted everything I know about the subject matter already in as much detail as I could. If anyone feels I could be more clear in some areas. Please let me know.
Time never ceases to accelerate.
DVIELIS
Posts: 2
Joined: Wed Jan 05, 2011 9:25 am
Location: Europe - Latvia

Post by DVIELIS »

I found the problem.... Back home from work, and look to zmfilter.pl file ... .

I look to zmfilter.pl code ....

.........................................

$smtp->auth(ZM_FROM_EMAIL, ZM_SMTP_PASSWORD) || die "Authentication failed!\n";

..................................................
And then i look to http://img208.imageshack.us/img208/7299 ... 004xb7.jpg
and saw

----FROM_EMAIL The email address you wish your event notifications to originate from (?) ZoneMinder@gmail.com

And then i understand where is my mistake ....
:oops: :lol: :D

When i want configure email settings like i send my self email, then i need write my email address in:

EMAIL_ADDRESS The email address to send matching event details to (?)

MESSAGE_ADDRESS The email address to send matching event details to (?)

FROM_EMAIL The email address you wish your event notifications to originate from (?)


my stupid mistake ... :evil:
I`m not sure, but i think the Earth is flat ..
nausser
Posts: 18
Joined: Sat Oct 09, 2010 9:08 pm
Location: South Florida

Post by nausser »

Glad you're up and running!

Cheers!
Time never ceases to accelerate.
Post Reply