markup: changes to success email (urls, no attach pdf)

This commit is contained in:
2020-03-11 15:47:56 -07:00
parent d90ea9b28a
commit ce5b92afd2

View File

@ -1,27 +1,38 @@
import sys
import string
import random
import re
import smtplib
from pathlib import Path
from mailbox import Maildir
import string
import sys
from email.header import Header, make_header
from email.message import EmailMessage
from email.utils import formatdate
from email.header import Header, make_header
from mailbox import Maildir
from pathlib import Path
from string import Template
from urllib.parse import quote
from procat2.settings import EMAIL_HOST, EMAIL_HOST_USER, EMAIL_HOST_PASSWORD
from procat2.settings import EMAIL_HOST, EMAIL_HOST_USER, EMAIL_HOST_PASSWORD, PUBLIC_WEB_HOST
import logging
log = logging.getLogger(__name__)
body_ok = """Hi,
body_ok = Template("""Hi,
Attached is a copy of your marked up catalog and a spreadsheet with
the articles you selected.
Attached is a spreadsheet with the articles you selected
in the marked up catalog:
$catname
Also, here are links to the marked up catalog and spreadsheet:
$caturl
$xlsurl
Enjoy,
ProCatalog Markup Bot
"""
""")
body_missing = """Hi,
@ -43,11 +54,21 @@ Thanks,
ProCatalog Markup Bot
"""
def path_to_url(path):
# from /opt/imagebank/mkbeta/markup/webdav/alx/markup/H2_party.xlsx
# to /export/markup/alx/markup/H2_party.xlsx
urlpath = re.sub(r"^(.*/markup/webdav/)", "/export/markup/", path)
url = f'https://{PUBLIC_WEB_HOST}{quote(urlpath)}'
log.debug(f'path_to_url: {url}')
return url
def reply(frm, subj, xls_path, pdf_path):
cat_url = path_to_url(pdf_path)
xls_url = path_to_url(xls_path)
body_text = body_ok.substitute(catname=subj, caturl=cat_url, xlsurl=xls_url)
msg = EmailMessage()
msg.set_content(body_ok)
subj = f'Re: {subj}'
msg.set_content(body_text)
with open(xls_path, 'rb') as fp:
msg.add_attachment(fp.read(),
@ -55,11 +76,11 @@ def reply(frm, subj, xls_path, pdf_path):
subtype='vnd.openxmlformats-officedocument.spreadsheetml.sheet',
filename=Path(xls_path).name)
with open(pdf_path, 'rb') as fp:
msg.add_attachment(fp.read(),
maintype='application',
subtype='pdf',
filename=Path(pdf_path).name)
# with open(pdf_path, 'rb') as fp:
# msg.add_attachment(fp.read(),
# maintype='application',
# subtype='pdf',
# filename=Path(pdf_path).name)
send(frm, subj, msg)