Beispiel #1
0
    def email_salary_slip(self):
        receiver = dataent.db.get_value("Employee", self.employee,
                                        "prefered_email")

        if receiver:
            email_args = {
                "recipients": [receiver],
                "message":
                _("Please see attachment"),
                "subject":
                'Salary Slip - from {0} to {1}'.format(self.start_date,
                                                       self.end_date),
                "attachments": [
                    dataent.attach_print(self.doctype,
                                         self.name,
                                         file_name=self.name)
                ],
                "reference_doctype":
                self.doctype,
                "reference_name":
                self.name
            }
            if not dataent.flags.in_test:
                enqueue(method=dataent.sendmail,
                        queue='short',
                        timeout=300,
                        is_async=True,
                        **email_args)
            else:
                dataent.sendmail(**email_args)
        else:
            msgprint(
                _("{0}: Employee email not found, hence email not sent").
                format(self.employee_name))
Beispiel #2
0
 def send_email(self):
     """send email with payment link"""
     email_args = {
         "recipients":
         self.email_to,
         "sender":
         None,
         "subject":
         self.subject,
         "message":
         self.get_message(),
         "now":
         True,
         "attachments": [
             dataent.attach_print(self.reference_doctype,
                                  self.reference_name,
                                  file_name=self.reference_name,
                                  print_format=self.print_format)
         ]
     }
     enqueue(method=dataent.sendmail,
             queue='short',
             timeout=300,
             is_async=True,
             **email_args)
Beispiel #3
0
 def get_attachments(self):
     attachments = [
         d.name for d in get_attachments(self.doctype, self.name)
     ]
     attachments.append(
         dataent.attach_print(self.doctype, self.name, doc=self))
     return attachments
Beispiel #4
0
def send_notification(new_rv, auto_repeat_doc, print_format='Standard'):
    """Notify concerned persons about recurring document generation"""
    print_format = print_format
    subject = auto_repeat_doc.subject or ''
    message = auto_repeat_doc.message or ''

    if not auto_repeat_doc.subject:
        subject = _("New {0}: #{1}").format(new_rv.doctype, new_rv.name)
    elif "{" in auto_repeat_doc.subject:
        subject = dataent.render_template(auto_repeat_doc.subject,
                                          {'doc': new_rv})

    if not auto_repeat_doc.message:
        message = _("Please find attached {0} #{1}").format(
            new_rv.doctype, new_rv.name)
    elif "{" in auto_repeat_doc.message:
        message = dataent.render_template(auto_repeat_doc.message,
                                          {'doc': new_rv})

    attachments = [
        dataent.attach_print(new_rv.doctype,
                             new_rv.name,
                             file_name=new_rv.name,
                             print_format=print_format)
    ]

    make(doctype=new_rv.doctype,
         name=new_rv.name,
         recipients=auto_repeat_doc.recipients,
         subject=subject,
         content=message,
         attachments=attachments,
         send_email=1)
Beispiel #5
0
def get_attachments(delivery_stop):
    if not (dataent.db.get_single_value("Delivery Settings",
                                        "send_with_attachment")
            and delivery_stop.delivery_note):
        return []

    dispatch_attachment = dataent.db.get_single_value("Delivery Settings",
                                                      "dispatch_attachment")
    attachments = dataent.attach_print("Delivery Note",
                                       delivery_stop.delivery_note,
                                       file_name="Delivery Note",
                                       print_format=dispatch_attachment)

    return [attachments]
Beispiel #6
0
def make_email_queue(email_queue):
	name_list = []
	for key, data in iteritems(email_queue):
		name = dataent.db.get_value('Sales Invoice', {'offline_pos_name': key}, 'name')
		data = json.loads(data)
		sender = dataent.session.user
		print_format = "POS Invoice" if not cint(dataent.db.get_value('Print Format', 'POS Invoice', 'disabled')) else None
		attachments = [dataent.attach_print('Sales Invoice', name, print_format=print_format)]

		make(subject=data.get('subject'), content=data.get('content'), recipients=data.get('recipients'),
                    sender=sender, attachments=attachments, send_email=True,
                    doctype='Sales Invoice', name=name)
		name_list.append(key)

	return name_list
Beispiel #7
0
def get_common_email_args(doc):
    doctype = doc.get('doctype')
    docname = doc.get('name')

    email_template = get_email_template(doc)
    if email_template:
        subject = dataent.render_template(email_template.subject, vars(doc))
        response = dataent.render_template(email_template.response, vars(doc))
    else:
        subject = _('Workflow Action')
        response = _('{0}: {1}'.format(doctype, docname))

    common_args = {
        'template': 'workflow_action',
        'attachments':
        [dataent.attach_print(doctype, docname, file_name=docname)],
        'subject': subject,
        'message': response
    }
    return common_args
Beispiel #8
0
def prepare_message(email, recipient, recipients_list):
	message = email.message
	if not message:
		return ""

	# Parse "Email Account" from "Email Sender"
	email_account = get_outgoing_email_account(raise_exception_not_set=False, sender=email.sender)
	if dataent.conf.use_ssl and email_account.track_email_status:
		# Using SSL => Publically available domain => Email Read Reciept Possible
		message = message.replace("<!--email open check-->", quopri.encodestring('<img src="https://{}/api/method/dataent.core.doctype.communication.email.mark_email_as_seen?name={}"/>'.format(dataent.local.site, email.communication).encode()).decode())
	else:
		# No SSL => No Email Read Reciept
		message = message.replace("<!--email open check-->", quopri.encodestring("".encode()).decode())

	if email.add_unsubscribe_link and email.reference_doctype: # is missing the check for unsubscribe message but will not add as there will be no unsubscribe url
		unsubscribe_url = get_unsubcribed_url(email.reference_doctype, email.reference_name, recipient,
		email.unsubscribe_method, email.unsubscribe_params)
		message = message.replace("<!--unsubscribe url-->", quopri.encodestring(unsubscribe_url.encode()).decode())

	if email.expose_recipients == "header":
		pass
	else:
		if email.expose_recipients == "footer":
			if isinstance(email.show_as_cc, string_types):
				email.show_as_cc = email.show_as_cc.split(",")
			email_sent_to = [r.recipient for r in recipients_list]
			email_sent_cc = ", ".join([e for e in email_sent_to if e in email.show_as_cc])
			email_sent_to = ", ".join([e for e in email_sent_to if e not in email.show_as_cc])

			if email_sent_cc:
				email_sent_message = _("This email was sent to {0} and copied to {1}").format(email_sent_to,email_sent_cc)
			else:
				email_sent_message = _("This email was sent to {0}").format(email_sent_to)
			message = message.replace("<!--cc message-->", quopri.encodestring(email_sent_message.encode()).decode())

		message = message.replace("<!--recipient-->", recipient)

	message = (message and message.encode('utf8')) or ''
	message = safe_decode(message)
	if not email.attachments:
		return message

	# On-demand attachments
	from email.parser import Parser

	msg_obj = Parser().parsestr(message)
	attachments = json.loads(email.attachments)

	for attachment in attachments:
		if attachment.get('fcontent'): continue

		fid = attachment.get("fid")
		if fid:
			fname, fcontent = get_file(fid)
			attachment.update({
				'fname': fname,
				'fcontent': fcontent,
				'parent': msg_obj
			})
			attachment.pop("fid", None)
			add_attachment(**attachment)

		elif attachment.get("print_format_attachment") == 1:
			attachment.pop("print_format_attachment", None)
			print_format_file = dataent.attach_print(**attachment)
			print_format_file.update({"parent": msg_obj})
			add_attachment(**print_format_file)

	return msg_obj.as_string()