Home
Help
Search
Login
Register
OPNsense Forum
»
English Forums
»
Tutorials and FAQs
»
Script to send emails for updates
« previous
next »
Print
Pages:
1
[
2
]
3
Author
Topic: Script to send emails for updates (Read 34810 times)
bartjsmit
Hero Member
Posts: 2016
Karma: 194
Re: Script to send emails for updates
«
Reply #15 on:
May 01, 2016, 08:54:02 pm »
RFC 2822 deals with message content. Can you try and edit the script to say 'text/plain' instead of 'text/html' or even remark out these two lines completely:
#message += 'MIME-Version: 1.0\n'
#message += 'Content-type: text/html\n'
Bart...
Logged
franco
Administrator
Hero Member
Posts: 17660
Karma: 1611
Re: Script to send emails for updates
«
Reply #16 on:
May 02, 2016, 08:00:48 am »
IMF is Internet Message Format, a.k.a. RFC 2822
Logged
franco
Administrator
Hero Member
Posts: 17660
Karma: 1611
Re: Script to send emails for updates
«
Reply #17 on:
May 02, 2016, 08:05:54 am »
I don't think the content headers matter, and I don't recall those being used by Email (MIME-Version and Content-type). Instead, maybe adhering to "\r\n" line breaks will help...
(And the last line dealing with reboot should probably also receive a newline.)
«
Last Edit: May 02, 2016, 08:07:55 am by franco
»
Logged
TheLatestWire
Jr. Member
Posts: 70
Karma: 6
Re: Script to send emails for updates
«
Reply #18 on:
May 02, 2016, 11:53:39 pm »
I tried using 'text/plain' instead of 'text/html', replacing all \n entries with \r\n and also tried remarking out both of these lines:
#message += 'MIME-Version: 1.0\n'
#message += 'Content-type: text/html\n'
but the script still comes back with "smtplib.SMTPDataError: (550, '5.7.1 Delivery not authorized, message refused: Message is not RFC 2822 compliant')"
Logged
TheLatestWire
Jr. Member
Posts: 70
Karma: 6
Re: Script to send emails for updates
«
Reply #19 on:
May 05, 2016, 03:07:38 pm »
This might be helpful. On the network where I'm able to use the script without the RFC 2822 compliant (it relays through a Linux Postfix system, not an OpenBSD SMTP server), I noticed this in my Amavis quarantine this morning even though the email from the script was delivered:
X-Amavis-Alert: BAD HEADER SECTION, Missing required header field: "Date"
Could a missing Date header field be what's upsetting the SMTP daemon on the OpenBSD SMTP server who refuses to accept the email from the script due to the RFC 2822 compliant?
Just a thought.
Thanks,
ObecalpEffect.
Logged
franco
Administrator
Hero Member
Posts: 17660
Karma: 1611
Re: Script to send emails for updates
«
Reply #20 on:
May 05, 2016, 03:23:29 pm »
The RFC states "The only required header fields are the origination date field and the originator address field(s). All other header fields are syntactically optional.". You may be right.
Logged
bartjsmit
Hero Member
Posts: 2016
Karma: 194
Re: Script to send emails for updates
«
Reply #21 on:
May 06, 2016, 08:44:15 am »
I'll have a dig through the smtplib docs to see if there is an option to add the timestamp to the email headers.
Bart...
Logged
TheLatestWire
Jr. Member
Posts: 70
Karma: 6
Re: Script to send emails for updates
«
Reply #22 on:
May 06, 2016, 08:21:44 pm »
I wish I could help, but I couldn't program my way out of a wet paper bag.
That said though, I was playing with getting a properly formatted date string with python while trying to get the script working and I think this would suffice and possibly be RFC 2822 compliant. I hope it's helpful. I'll try to poke through the smtplib docs too and see if I can find a way to add the date header. Hopefully it is the date header that is causing OpenBSD's SMTP daemon to complain about RFC 2822 compliancy and we're not chasing our tails here.
#!/usr/local/bin/python
# import libraries
from email.Utils import formatdate
print formatdate(localtime = 6)
Logged
TheLatestWire
Jr. Member
Posts: 70
Karma: 6
Re: Script to send emails for updates
«
Reply #23 on:
May 06, 2016, 08:33:47 pm »
Hmm, not sure if I'm dreaming this or not, but I think I fixed it with the addition of these three lines in the script:
from email.Utils import formatdate
and
dateheader = 'formatdate(localtime = 6)\r\n'
and
message += '\r\ndateheader\r\n
So the entire top section of the script now looks like this (and it actually worked!
)
#!/usr/local/bin/python
# import libraries
import json
import requests
import smtplib
from email.Utils import formatdate
api_key = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
api_secret = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
host = 'localhost'
recipients = 'me@there.edu'
rcpt_name = 'First Last'
dateheader = 'formatdate(localtime = 6)\r\n'
url = 'https://' + host + '/api/core/firmware/status'
sender = 'emailrelay@there.edu'
message = 'From: emailrelay@there.edu\r\n'
message += 'To: me@there.edu>\r\n'
message += 'MIME-Version: 1.0\r\n'
message += 'Content-type: text/html\r\n'
message += 'Subject: Updates Available for OPNsense\r\n'
message += '\r\ndateheader\r\n'
# request and process data
«
Last Edit: May 06, 2016, 08:46:23 pm by ObecalpEffect
»
Logged
bartjsmit
Hero Member
Posts: 2016
Karma: 194
Re: Script to send emails for updates
«
Reply #24 on:
May 07, 2016, 12:33:34 am »
Thanks for that - looks to me like a pretty sturdy paper bag ;-)
I'll do some regression testing with postfix and attach a new version to this thread.
Bart...
Logged
fabian
Hero Member
Posts: 2769
Karma: 200
OPNsense Contributor (Language, VPN, Proxy, etc.)
Re: Script to send emails for updates
«
Reply #25 on:
May 07, 2016, 10:35:53 am »
You could also use a public git repository
Logged
bartjsmit
Hero Member
Posts: 2016
Karma: 194
Re: Script to send emails for updates
«
Reply #26 on:
May 07, 2016, 04:07:28 pm »
Also published on
https://github.com/bartsmit/opnsense-update-email
ObecalpEffect, I've credited you with your forum handle.
Bart...
Logged
TheLatestWire
Jr. Member
Posts: 70
Karma: 6
Re: Script to send emails for updates
«
Reply #27 on:
May 26, 2016, 05:22:32 pm »
Hi Bart,
Sorry to be a pain, but I noticed that the latest version of the script still isn't working with SMTP on my OpenBSD server. SMTP on OpenBSD still complains "Message is not RFC 2822 compliant".
I was however able to get it working by replacing this line:
message += formatdate(localtime=True) + '\r\n'
With this line:
message += 'Date: = formatdate(localtime=True)'
*Please also note that it doesn't work when the line is appended with + '\r\n'
Thanks,
Obecalp.
Logged
bartjsmit
Hero Member
Posts: 2016
Karma: 194
Re: Script to send emails for updates
«
Reply #28 on:
May 26, 2016, 10:29:33 pm »
Thanks Obecalp,
I will do some regression testing and post an updated script.
Bart...
Logged
tessus
Jr. Member
Posts: 67
Karma: 2
Re: Script to send emails for updates
«
Reply #29 on:
May 27, 2022, 05:10:45 am »
The JSON response from OPNsense looks a bit different now. I have updated the script accordingly and made it python3 compatible.
Logged
Print
Pages:
1
[
2
]
3
« previous
next »
OPNsense Forum
»
English Forums
»
Tutorials and FAQs
»
Script to send emails for updates