else:
logging.warn('accessing %s failed: %s' % (service, result))
self.finish_json({'error': result})
+
+ elif utils.remote_camera(camera_config):
+ def on_response(result=None, error=None):
+ if result is True:
+ self.finish_json()
+
+ else:
+ result = result or error
+ self.finish_json({'error': result})
+
+ remote.test(camera_config, data, on_response)
+
+ elif what == 'email':
+ import sendmail
+ import tzctl
+ import smtplib
+
+ if utils.local_motion_camera(camera_config):
+ logging.debug('testing notification email')
+
+ try:
+ subject = sendmail.subjects['motion_start']
+ message = sendmail.messages['motion_start']
+ format_dict = {
+ 'camera': camera_config['@name'],
+ 'hostname': socket.gethostname(),
+ 'moment': datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'),
+ }
+ if settings.LOCAL_TIME_FILE:
+ format_dict['timezone'] = tzctl.get_time_zone()
+
+ else:
+ format_dict['timezone'] = 'local time'
+
+ message = message % format_dict
+ subject = subject % format_dict
+
+ old_timeout = settings.SMTP_TIMEOUT
+ settings.SMTP_TIMEOUT = 10
+ sendmail.send_mail(data['smtp_server'], int(data['smtp_port']), data['smtp_account'], data['smtp_password'], data['smtp_tls'],
+ data['from'], [data['addresses']], subject=subject, message=message, files=[])
+ settings.SMTP_TIMEOUT = old_timeout
+
+ self.finish_json()
+
+ except Exception as e:
+ if isinstance(e, smtplib.SMTPResponseException):
+ msg = e.smtp_error
+
+ else:
+ msg = str(e)
+
+ msg_lower = msg.lower()
+ if msg_lower.count('tls'):
+ msg = 'TLS might be required'
+
+ elif msg_lower.count('authentication'):
+ msg = 'authentication error'
+
+ elif msg_lower.count('name or service not known'):
+ msg = 'check SMTP server name'
+
+ elif msg_lower.count('connection refused'):
+ msg = 'check SMTP port'
+
+ logging.error('notification email test failed: %s' % msg, exc_info=True)
+ self.finish_json({'error': str(msg)})
elif utils.remote_camera(camera_config):
def on_response(result=None, error=None):
});
}
+function doTestEmail() {
+ var q = $('#emailAddressesEntry, #smtpServerEntry, #smtpPortEntry');
+ var valid = true;
+ q.each(function() {
+ this.validate();
+ if (this.invalid) {
+ valid = false;
+ }
+ });
+
+ if (!valid) {
+ return runAlertDialog('Make sure all the configuration options are valid!');
+ }
+
+ showModalDialog('<div class="modal-progress"></div>', null, null, true);
+
+ var data = {
+ what: 'email',
+ from: $('#emailFromEntry').val(),
+ addresses: $('#emailAddressesEntry').val(),
+ smtp_server: $('#smtpServerEntry').val(),
+ smtp_port: $('#smtpPortEntry').val(),
+ smtp_account: $('#smtpAccountEntry').val(),
+ smtp_password: $('#smtpPasswordEntry').val(),
+ smtp_tls: $('#smtpTlsSwitch')[0].checked
+ };
+
+ var cameraId = $('#cameraSelect').val();
+
+ ajax('POST', basePath + 'config/' + cameraId + '/test/', data, function (data) {
+ hideModalDialog(); /* progress */
+ if (data.error) {
+ showErrorMessage('Notification email failed: ' + data.error + '!');
+ }
+ else {
+ showPopupMessage('Notification email succeeded!', 'info');
+ }
+ });
+}
+
function doDownloadZipped(cameraId, groupKey) {
showModalDialog('<div class="modal-progress"></div>', null, null, true);
ajax('GET', basePath + 'picture/' + cameraId + '/zipped/' + groupKey + '/', null, function (data) {
/* test buttons */
$('div#uploadTestButton').click(doTestUpload);
+ $('div#emailTestButton').click(doTestEmail);
initUI();
beginProgress();
<td class="settings-item-value"><input type="text" class="number styled notifications camera-config" id="emailPictureTimeSpanEntry"><span class="settings-item-unit">seconds</span></td>
<td><span class="help-mark" title="defines the picture search time interval to use when creating email attachments (higher values generate emails with more pictures at the cost of an increased notification delay); set to 0 to disable picture attachments">?</span></td>
</tr>
+ <tr class="settings-item advanced-setting" depends="emailNotificationsEnabled motionDetectionEnabled">
+ <td class="settings-item-label"><span class="settings-item-label"></span></td>
+ <td class="settings-item-value"><div class="button normal-button test-button" id="emailTestButton">Test Email</div></td>
+ <td><span class="help-mark" title="click this button to test email notifications after you have filled in the required details">?</span></td>
+ </tr>
<tr class="settings-item advanced-setting" depends="motionDetectionEnabled">
<td colspan="100"><div class="settings-item-separator"></div></td>
</tr>