English Forums > Tutorials and FAQs

Script to send emails for updates

<< < (5/7) > >>

franco:
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. :)

bartjsmit:
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...

TheLatestWire:
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)

TheLatestWire:
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

bartjsmit:
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...

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version