Esempio n. 1
0
 def is_in_mail_history(self, company):
     """
     Return True if this file is already in the mail history
     (based on the md5 sum of the content)
     :param obj company: The company to which this file should have been sent
     """
     return check_if_mail_sent(
         open(self.path, 'r').read(),
         company.id,
     )
Esempio n. 2
0
 def is_in_mail_history(self, company):
     """
     Return True if this file is already in the mail history
     (based on the md5 sum of the content)
     :param obj company: The company to which this file should have been sent
     """
     return check_if_mail_sent(
         open(self.path, 'r').read(),
         company.id,
     )
Esempio n. 3
0
def send_salary_sheet(request,
                      email,
                      company_id,
                      filename,
                      filepath,
                      force=False,
                      message=None,
                      subject=None):
    """
    Send a salarysheet to the given company's e-mail

    :param obj request: A pyramid request object
    :param str company_mail: The mail to send it to
    :param int company_id: The id of the associated company
    :param str filepath: The path to the filename
    :param bool force: Whether to force sending this file again
    :param str message: The mail message
    :param str subject: The mail subject
    :returns: A MailHistory instance
    :TypeError UndeliveredMail: When the company has no mail
    :TypeError MailAlreadySent: if the file has
        already been sent and no force option was passed
    """
    filebuf = file(filepath, 'r')
    filedatas = filebuf.read()

    if not force and check_if_mail_sent(filedatas, company_id):
        log.warn(u"Mail already sent : mail already sent")
        raise MailAlreadySent(u"Mail already sent")

    filebuf.seek(0)

    if email is None:
        log.warn(
            u"Undelivered email : no mail provided for company {0}".format(
                company_id))
        raise UndeliveredMail(
            u"no mail provided for company {0}".format(company_id))
    else:
        log.info('Sending the file %s' % filepath)
        log.info("Sending it to %s" % email)
        attachment = Attachment(filename, "application/pdf", filebuf)

        subject = subject or SALARYSHEET_MAIL_SUBJECT
        message = message or SALARYSHEET_MAIL_MESSAGE

        send_mail(
            request,
            email,
            message,
            subject,
            attachment,
        )
        return store_sent_mail(filepath, filedatas, company_id)