Page 2 of 2

Posted: Sat Mar 07, 2009 5:29 am
by muckleroy
Hmmm if memory serves that is all it returned for me, thats why I added the yourdomain stuff.

Just a guess, but you may need to go back to your zoneminder options and see how you have the various parameters set.

Posted: Thu Mar 12, 2009 1:13 pm
by Voltage54
Argh! I still can't manage to get it to work.

I'm quite sure all the settings in the zoneminder web config are correct, however I realised that even if I make it work, I require a username/pass to access the http:// connection of zoneminder, so wouldn't it block my email client from viewing the picture anyway?

Viewing carteriii's original code (if you click the quote button on his post, you can see the plain text source code to avoid any problems with the <bcode> option), it seems to indicate that a *.jpg is attached in the email, rather than linked to (via http://yourdomain.com/zm/....picture.jpg). I have tried both sets of code he has provided and neither work for me... I keep getting a little box with a red cross in it in the place of the 'inline_image1'.

Has anyone managed to get this to work? Please let me know how you solved your problem.. It's really starting to frustrate me as I get quite a few emails per day and having to open each email, save the picture, then open the picture is driving me nuts :(

Posted: Thu Mar 12, 2009 2:14 pm
by muckleroy
Voltage54 wrote:Argh! I still can't manage to get it to work.

I'm quite sure all the settings in the zoneminder web config are correct, however I realised that even if I make it work, I require a username/pass to access the http:// connection of zoneminder, so wouldn't it block my email client from viewing the picture anyway?

Viewing carteriii's original code (if you click the quote button on his post, you can see the plain text source code to avoid any problems with the <bcode> option), it seems to indicate that a *.jpg is attached in the email, rather than linked to (via http://yourdomain.com/zm/....picture.jpg). I have tried both sets of code he has provided and neither work for me... I keep getting a little box with a red cross in it in the place of the 'inline_image1'.

Has anyone managed to get this to work? Please let me know how you solved your problem.. It's really starting to frustrate me as I get quite a few emails per day and having to open each email, save the picture, then open the picture is driving me nuts :(
Can you post up the contents of the e-mail you are receiving?

Posted: Sat Mar 14, 2009 4:50 am
by Voltage54
nope because I got it working :D:D

For some reason, when the script is set to multipart/alternative ... the images will refuse to load. On multipart/mixed it works (and adds the plain text part as an attachment... which I can live with).

Anyway, the end result is (I believe this is a direct copy from the first post in this thread, however just for clarity):

zmfilter.pl:

sub sendEmail
{
my $filter = shift;
my $event = shift;

if ( !ZM_FROM_EMAIL )
{
warn( "No 'from' email address defined, not sending email" );
return( 0 );
}
if ( !ZM_EMAIL_ADDRESS )
{
warn( "No email address defined, not sending email" );
return( 0 );
}

Info( "Creating notification email\n" );

my $subject = substituteTags( ZM_EMAIL_SUBJECT, $filter, $event );
return( 0 ) if ( !$subject );
my @attachments;
my $body = substituteTags( ZM_EMAIL_BODY, $filter, $event, \@attachments );
return( 0 ) if ( !$body );

Info( "Sending notification email '$subject'\n" );

eval
{
if ( ZM_NEW_MAIL_MODULES )
{
### Create the multipart container
my $mail = MIME::Lite->new (
From => ZM_FROM_EMAIL,
To => ZM_EMAIL_ADDRESS,
Subject => $subject,
Type => "multipart/mixed"
);

### Create an image tag for each attachment
my $attachment_count = 0;
my $img_tags = "";
foreach my $attachment ( @attachments )
{
$attachment_count++;
$img_tags .= qq {<img src="cid:inline_image$attachment_count"><br>};
}

### Add an html message part
$mail->attach (
Type => "text/html",
Data => qq {<body>$img_tags<br>$body</body>}
);

### Add the text message part
$mail->attach (
Type => "TEXT",
Data => $body
);
### Add the attachments
### Add the counter to create an image Id
### Note that is must be declared "my" or else it will
### be considered global and cause the entire zmfilter.pl to fail
$attachment_count = 0;
foreach my $attachment ( @attachments )
{
Info( "Attaching '$attachment->{path}\n" );
$mail->attach(
Path => $attachment->{path},
Type => $attachment->{type},
Id => ('inline_image' . ++$attachment_count),
Disposition => "attachment"
);
}
### Send the Message
MIME::Lite->send( "smtp", ZM_EMAIL_HOST, Timeout=>60 );
$mail->send();
}
else
{
my $mail = MIME::Entity->build(
From => ZM_FROM_EMAIL,
To => ZM_EMAIL_ADDRESS,
Subject => $subject,
Type => (($body=~/<html>/)?'text/html':'text/plain'),
Data => $body
);

foreach my $attachment ( @attachments )
{
Info( "Attaching '$attachment->{path}\n" );
$mail->attach(
Path => $attachment->{path},
Type => $attachment->{type},
Encoding => "base64"
);
}
$mail->smtpsend( Host => ZM_EMAIL_HOST, MailFrom => ZM_FROM_EMAIL );
}
};
if ( $@ )
{
warn( "Can't send email: $@" );
return( 0 );
}
else
{
Info( "Notification email sent\n" );
}
my $sql = "update Events set Emailed = 1 where Id = ?";
my $sth = $dbh->prepare_cached( $sql ) or Fatal( "Can't prepare '$sql': ".$dbh->errstr() );
my $res = $sth->execute( $event->{Id} ) or Fatal( "Can't execute '$sql': ".$sth->errstr() );

return( 1 );
}


And, the ZM_EMAIL_BODY:

%EI1%

%EIM%

<b>WARNING!</b><br><br>
An alarm has been detected on your installation of ZoneMinder.<br><br>

The alarm occurred at <b>%MN%</b> at %ET%.<br><br>

The cause was %EC%, with a maximum event score of %ESM%.<br><br>

Currently, there are %MET% total events logged at %MN%.<br><br>

This alarm was matched by the %FN% filter and can be viewed at<br>
<br>
<A href="%EPS%">http://yourdomain.com/zm</A>

NB: I have ZM_NEW_MAIL_MODULES selected

Posted: Sat Mar 14, 2009 8:38 am
by muckleroy
Good job, now just sit back and enjoy!

Posted: Mon Feb 07, 2011 11:45 am
by insippo
Voltage54 wrote:nope because I got it working :D:D

For some reason, when the script is set to multipart/alternative ... the images will refuse to load. On multipart/mixed it works (and adds the plain text part as an attachment... which I can live with).

Anyway, the end result is (I believe this is a direct copy from the first post in this thread, however just for clarity):

zmfilter.pl:

sub sendEmail
{
my $filter = shift;
my $event = shift;

if ( !ZM_FROM_EMAIL )
{
warn( "No 'from' email address defined, not sending email" );
return( 0 );
}
if ( !ZM_EMAIL_ADDRESS )
{
warn( "No email address defined, not sending email" );
return( 0 );
}

Info( "Creating notification email\n" );

my $subject = substituteTags( ZM_EMAIL_SUBJECT, $filter, $event );
return( 0 ) if ( !$subject );
my @attachments;
my $body = substituteTags( ZM_EMAIL_BODY, $filter, $event, \@attachments );
return( 0 ) if ( !$body );

Info( "Sending notification email '$subject'\n" );

eval
{
if ( ZM_NEW_MAIL_MODULES )
{
### Create the multipart container
my $mail = MIME::Lite->new (
From => ZM_FROM_EMAIL,
To => ZM_EMAIL_ADDRESS,
Subject => $subject,
Type => "multipart/mixed"
);

### Create an image tag for each attachment
my $attachment_count = 0;
my $img_tags = "";
foreach my $attachment ( @attachments )
{
$attachment_count++;
$img_tags .= qq {<img><br>};
}

### Add an html message part
$mail->attach (
Type => "text/html",
Data => qq {<body>$img_tags<br>$body</body>}
);

### Add the text message part
$mail->attach (
Type => "TEXT",
Data => $body
);
### Add the attachments
### Add the counter to create an image Id
### Note that is must be declared "my" or else it will
### be considered global and cause the entire zmfilter.pl to fail
$attachment_count = 0;
foreach my $attachment ( @attachments )
{
Info( "Attaching '$attachment->{path}\n" );
$mail->attach(
Path => $attachment->{path},
Type => $attachment->{type},
Id => ('inline_image' . ++$attachment_count),
Disposition => "attachment"
);
}
### Send the Message
MIME::Lite->send( "smtp", ZM_EMAIL_HOST, Timeout=>60 );
$mail->send();
}
else
{
my $mail = MIME::Entity->build(
From => ZM_FROM_EMAIL,
To => ZM_EMAIL_ADDRESS,
Subject => $subject,
Type => (($body=~/<html>/)?'text/html':'text/plain'),
Data => $body
);

foreach my $attachment ( @attachments )
{
Info( "Attaching '$attachment->{path}\n" );
$mail->attach(
Path => $attachment->{path},
Type => $attachment->{type},
Encoding => "base64"
);
}
$mail->smtpsend( Host => ZM_EMAIL_HOST, MailFrom => ZM_FROM_EMAIL );
}
};
if ( $@ )
{
warn( "Can't send email: $@" );
return( 0 );
}
else
{
Info( "Notification email sent\n" );
}
my $sql = "update Events set Emailed = 1 where Id = ?";
my $sth = $dbh->prepare_cached( $sql ) or Fatal( "Can't prepare '$sql': ".$dbh->errstr() );
my $res = $sth->execute( $event->{Id} ) or Fatal( "Can't execute '$sql': ".$sth->errstr() );

return( 1 );
}


And, the ZM_EMAIL_BODY:

%EI1%

%EIM%

<b>WARNING!</b><br><br>
An alarm has been detected on your installation of ZoneMinder.<br><br>

The alarm occurred at <b>%MN%</b> at %ET%.<br><br>

The cause was %EC%, with a maximum event score of %ESM%.<br><br>

Currently, there are %MET% total events logged at %MN%.<br><br>

This alarm was matched by the %FN% filter and can be viewed at<br>
<br>
<A>http://yourdomain.com/zm</A>

NB: I have ZM_NEW_MAIL_MODULES selected
Is it necessary to new file a zmfilter.pl such content?

Re: send html email w/inline images

Posted: Tue Jan 24, 2012 9:49 am
by kazy
Hi, all

Forgive my leak of knowlage, but i'm pretty new on linux - zoneminder - perl scripts :)

This script is for add more pictures to mail alerts notification ?
Or just to show alerts pictures in mail content ?

I search a way to send to send a bundle of alerts pictures ( something like 1 picture for every 3 sec of the event) instead of a video. But zoneminder only accept "Firt" and "Max score" picture attachement.

This script can help me ?

thx

Re: send html email w/inline images

Posted: Thu Feb 16, 2023 12:52 am
by iconnor
So this is an old thread. Just wanted to say that I merged the ideas here into current master. 1.37.31. attached images are now inline.