The python libraries will *append* a header if it's just added again,
which would cause the news to go out with two date headers. Oops. So
instead check if each header is present and in that case replace it
rather than appending.
elif not usergenerated:
msg['Auto-Submitted'] = 'auto-generated'
- for h in headers.keys():
- msg[h] = headers[h]
+ for h, v in headers.items():
+ if h in msg:
+ # Replace the existing header -- the one specified is supposedly overriding it
+ msg.replace_header(h, v)
+ else:
+ msg.add_header(h, v)
if htmlbody:
mpart = MIMEMultipart("alternative")