if ui['email_notifications_enabled']:
emails = re.sub('\\s', '', ui['email_notifications_addresses'])
- on_event_start.append("%(script)s '%(server)s' '%(port)s' '%(account)s' '%(password)s' '%(tls)s' '%(to)s' 'motion_start' '%%t' '%%Y-%%m-%%dT%%H:%%M:%%S' '%(timespan)s'" % {
+ on_event_start.append("%(script)s '%(server)s' '%(port)s' '%(account)s' '%(password)s' '%(tls)s' '%(from)s' '%(to)s' 'motion_start' '%%t' '%%Y-%%m-%%dT%%H:%%M:%%S' '%(timespan)s'" % {
'script': meyectl.find_command('sendmail'),
'server': ui['email_notifications_smtp_server'],
'port': ui['email_notifications_smtp_port'],
'account': ui['email_notifications_smtp_account'],
'password': ui['email_notifications_smtp_password'].replace(';', '\\;').replace('%', '%%'),
'tls': ui['email_notifications_smtp_tls'],
+ 'from': ui['email_notifications_from'],
'to': emails,
'timespan': ui['email_notifications_picture_time_span']})
if len(e) < 10:
continue
-
+
+ if len(e) < 16:
+ # backwards compatibility with older configs lacking "from" field
+ e.insert(-5, '')
+
ui['email_notifications_enabled'] = True
- ui['email_notifications_smtp_server'] = e[-10]
- ui['email_notifications_smtp_port'] = e[-9]
- ui['email_notifications_smtp_account'] = e[-8]
- ui['email_notifications_smtp_password'] = e[-7].replace('\\;', ';').replace('%%', '%')
- ui['email_notifications_smtp_tls'] = e[-6].lower() == 'true'
+ ui['email_notifications_smtp_server'] = e[-11]
+ ui['email_notifications_smtp_port'] = e[-10]
+ ui['email_notifications_smtp_account'] = e[-9]
+ ui['email_notifications_smtp_password'] = e[-8].replace('\\;', ';').replace('%%', '%')
+ ui['email_notifications_smtp_tls'] = e[-7].lower() == 'true'
+ ui['email_notifications_from'] = e[-6]
ui['email_notifications_addresses'] = e[-5]
try:
ui['email_notifications_picture_time_span'] = int(e[-1])
-
+
except:
ui['email_notifications_picture_time_span'] = 0
}
-def send_mail(server, port, account, password, tls, to, subject, message, files):
+def send_mail(server, port, account, password, tls, _from, to, subject, message, files):
conn = smtplib.SMTP(server, port, timeout=settings.SMTP_TIMEOUT)
if tls:
conn.starttls()
if account and password:
conn.login(account, password)
- _from = 'motionEye on %s <%s>' % (socket.gethostname(), to[0])
-
email = MIMEMultipart()
email['Subject'] = subject
email['From'] = _from
parser.add_argument('account', help='SMTP account name (username)')
parser.add_argument('password', help='SMTP account password')
parser.add_argument('tls', help='"true" to use TLS')
+ parser.add_argument('from', help='the email from field')
parser.add_argument('to', help='the email recipient(s)')
parser.add_argument('msg_id', help='the identifier of the message')
parser.add_argument('thread_id', help='the id of the motion thread')
# or otherwise media listing won't work
signal.signal(signal.SIGCHLD,signal.SIG_DFL)
+ if len(args) == 12:
+ # backwards compatibility with older configs lacking "from" field
+ _from = 'motionEye on %s <%s>' % (socket.gethostname(), args[7].split(',')[0])
+ args = args[:7] + [_from] + args[7:]
+
+ if not args[7]:
+ args[7] = 'motionEye on %s <%s>' % (socket.gethostname(), args[8].split(',')[0])
+
options = parse_options(parser, args)
meyectl.configure_logging('sendmail', options.log_to_file)
settings.LIST_MEDIA_TIMEOUT = settings.LIST_MEDIA_TIMEOUT_EMAIL
camera_id = motionctl.thread_id_to_camera_id(options.thread_id)
+ _from = getattr(options, 'from')
logging.debug('server = %s' % options.server)
logging.debug('port = %s' % options.port)
logging.debug('password = ******')
logging.debug('server = %s' % options.server)
logging.debug('tls = %s' % str(options.tls).lower())
+ logging.debug('from = %s' % _from)
logging.debug('to = %s' % options.to)
logging.debug('msg_id = %s' % options.msg_id)
logging.debug('thread_id = %s' % options.thread_id)
def on_message(subject, message, files):
try:
send_mail(options.server, options.port, options.account, options.password,
- options.tls, to, subject, message, files or [])
+ options.tls, _from, to, subject, message, files or [])
logging.info('email sent')
except Exception as e:
return true;
}, '');
+ makeCustomValidator($('#emailFromEntry'), function (value) {
+ if (value && !value.toLowerCase().match(new RegExp('^[a-z0-9\-\_\+\.\@\^\~\<>, ]+$'))) {
+ return 'enter a vaild email address';
+ }
+
+ return true;
+ }, '');
makeCustomValidator($('#emailAddressesEntry'), function (value) {
if (!value.toLowerCase().match(new RegExp('^[a-z0-9\-\_\+\.\@\^\~\, ]+$'))) {
return 'enter a list of comma-separated valid email addresses';
/* motion notifications */
'email_notifications_enabled': $('#emailNotificationsEnabledSwitch')[0].checked,
+ 'email_notifications_from': $('#emailFromEntry').val(),
'email_notifications_addresses': $('#emailAddressesEntry').val(),
'email_notifications_smtp_server': $('#smtpServerEntry').val(),
'email_notifications_smtp_port': $('#smtpPortEntry').val(),
/* motion notifications */
$('#emailNotificationsEnabledSwitch')[0].checked = dict['email_notifications_enabled']; markHideIfNull('email_notifications_enabled', 'emailNotificationsEnabledSwitch');
+ $('#emailFromEntry').val(dict['email_notifications_from']);
$('#emailAddressesEntry').val(dict['email_notifications_addresses']);
$('#smtpServerEntry').val(dict['email_notifications_smtp_server']);
$('#smtpPortEntry').val(dict['email_notifications_smtp_port']);
<td class="settings-item-value"><input type="password" class="styled notifications camera-config" id="smtpPasswordEntry"></td>
<td><span class="help-mark" title="enter your SMTP account password (for Gmail use your Google password or an app-specific generated password)">?</span></td>
</tr>
+ <tr class="settings-item advanced-setting" depends="emailNotificationsEnabled motionDetectionEnabled" strip="true">
+ <td class="settings-item-label"><span class="settings-item-label">From Address</span></td>
+ <td class="settings-item-value"><input type="text" class="styled notifications camera-config" id="emailFromEntry" placeholder="email address..."></td>
+ <td><span class="help-mark" title="set a custom From address, if your SMTP service requires one (the first destination email address will be used if left blank)">?</span></td>
+ </tr>
<tr class="settings-item advanced-setting" depends="emailNotificationsEnabled motionDetectionEnabled">
<td class="settings-item-label"><span class="settings-item-label">Use TLS</span></td>
<td class="settings-item-value"><input type="checkbox" class="styled notifications camera-config" id="smtpTlsSwitch"></td>