sending email reminders with bcc to phuoc
This commit is contained in:
@@ -11,8 +11,6 @@ from pyramid.httpexceptions import (
|
|||||||
HTTPForbidden,
|
HTTPForbidden,
|
||||||
)
|
)
|
||||||
|
|
||||||
from pyramid_mailer import get_mailer
|
|
||||||
from pyramid_mailer.message import Message, Attachment
|
|
||||||
from datetime import *
|
from datetime import *
|
||||||
from dateutil.relativedelta import *
|
from dateutil.relativedelta import *
|
||||||
from docutils.core import publish_parts
|
from docutils.core import publish_parts
|
||||||
@@ -617,7 +615,7 @@ def societes(request):
|
|||||||
liste=[]
|
liste=[]
|
||||||
for item in items:
|
for item in items:
|
||||||
modif_le = item.modif_le.strftime('%d/%m/%Y')
|
modif_le = item.modif_le.strftime('%d/%m/%Y')
|
||||||
d = (item.societe, item.NOM, item.email_from, item.TEL, item.bic, item.iban, modif_le)
|
d = (item.societe, item.NOM, item.email_from, item.TEL, item.email_cci, item.iban, modif_le)
|
||||||
liste.append(d)
|
liste.append(d)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -150,9 +150,11 @@ def email_rappels(request, objet, corps, destinataire, societe):
|
|||||||
msg['Subject'] = "[Ent. Dumas] " + objet
|
msg['Subject'] = "[Ent. Dumas] " + objet
|
||||||
msg['From'] = smtp_user
|
msg['From'] = smtp_user
|
||||||
msg['To'] = destinataire
|
msg['To'] = destinataire
|
||||||
|
msg['Bcc'] = "phuoc@caotek.fr"
|
||||||
msg.set_content(corps, subtype='html')
|
msg.set_content(corps, subtype='html')
|
||||||
|
|
||||||
# Try to log in to server and send email
|
# Try to log in to server and send email
|
||||||
|
err = ''
|
||||||
try:
|
try:
|
||||||
server = smtplib.SMTP(smtp_server,smtp_port)
|
server = smtplib.SMTP(smtp_server,smtp_port)
|
||||||
server.starttls(context=context) # Secure the connection
|
server.starttls(context=context) # Secure the connection
|
||||||
@@ -162,16 +164,18 @@ def email_rappels(request, objet, corps, destinataire, societe):
|
|||||||
print("sendmail -> OK")
|
print("sendmail -> OK")
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
# Print any error messages to stdout
|
# Just print(e) is cleaner and more likely what you want,
|
||||||
print(e)
|
# but if you insist on printing message specifically whenever possible...
|
||||||
|
err = repr(e)[0:400]
|
||||||
|
insert_log(request, 'MAILER', "- ERROR : %s, TO : %s" % (err, destinataire))
|
||||||
finally:
|
finally:
|
||||||
server.quit()
|
server.quit()
|
||||||
|
|
||||||
return 0
|
return len(err)
|
||||||
|
|
||||||
def email_rapport(request):
|
def email_rapport(request):
|
||||||
NOW = datetime.now()
|
NOW = datetime.now()
|
||||||
corps = "<html><body><p>=============================================</p>"
|
corps = "<!DOCTYPE html><html><body><p>=============================================</p>"
|
||||||
corps += "<p>Rapport du traitement de nuit du " + NOW.strftime('%d/%m/%Y - %H:%M') + "</p>"
|
corps += "<p>Rapport du traitement de nuit du " + NOW.strftime('%d/%m/%Y - %H:%M') + "</p>"
|
||||||
corps += "<p>=============================================</p><p></p><p>"
|
corps += "<p>=============================================</p><p></p><p>"
|
||||||
|
|
||||||
@@ -190,15 +194,12 @@ def email_rapport(request):
|
|||||||
|
|
||||||
|
|
||||||
def send_mail(request, expediteur, destinataires, objet, corps):
|
def send_mail(request, expediteur, destinataires, objet, corps):
|
||||||
body = """
|
body_html = Attachment(data=corps, transfer_encoding="base64", disposition='inline')
|
||||||
|
|
||||||
%s
|
|
||||||
""" % (corps)
|
|
||||||
|
|
||||||
message = Message(subject=objet,
|
message = Message(subject=objet,
|
||||||
sender=expediteur,
|
sender=expediteur,
|
||||||
recipients=destinataires,
|
recipients=destinataires,
|
||||||
html=body)
|
html=body_html)
|
||||||
mailer = get_mailer(request)
|
mailer = get_mailer(request)
|
||||||
msg = ''
|
msg = ''
|
||||||
try:
|
try:
|
||||||
|
|||||||
Reference in New Issue
Block a user