Example #1
0
    def test_unsubscribe(self):
        from frappe.email.bulk import unsubscribe, send
        unsubscribe(doctype="User",
                    name="Administrator",
                    email="*****@*****.**")

        self.assertTrue(
            frappe.db.get_value(
                "Email Unsubscribe", {
                    "reference_doctype": "User",
                    "reference_name": "Administrator",
                    "email": "*****@*****.**"
                }))

        send(recipients=['*****@*****.**', '*****@*****.**'],
             sender="*****@*****.**",
             reference_doctype='User',
             reference_name="Administrator",
             subject='Testing Bulk',
             message='This is a bulk mail!')

        bulk = frappe.db.sql(
            """select * from `tabBulk Email` where status='Not Sent'""",
            as_dict=1)
        self.assertEquals(len(bulk), 1)
        self.assertFalse('*****@*****.**' in [d['recipient'] for d in bulk])
        self.assertTrue('*****@*****.**' in [d['recipient'] for d in bulk])
        self.assertTrue('Unsubscribe' in bulk[0]['message'])
Example #2
0
    def send_bulk(self):
        if not self.get("recipients"):
            # in case it is called via worker
            self.recipients = self.get_recipients()

        self.validate_send()

        sender = self.send_from or frappe.utils.get_formatted_email(self.owner)

        from frappe.email.bulk import send

        if not frappe.flags.in_test:
            frappe.db.auto_commit_on_many_writes = True

        send(recipients=self.recipients,
             sender=sender,
             subject=self.subject,
             message=self.message,
             doctype=self.send_to_doctype,
             email_field=self.get("email_field") or "email_id",
             ref_doctype=self.doctype,
             ref_docname=self.name)

        if not frappe.flags.in_test:
            frappe.db.auto_commit_on_many_writes = False
Example #3
0
    def send_bulk(self):
        if not self.get("recipients"):
            # in case it is called via worker
            self.recipients = self.get_recipients()

        self.validate_send()

        sender = self.send_from or frappe.utils.get_formatted_email(self.owner)

        if not frappe.flags.in_test:
            frappe.db.auto_commit_on_many_writes = True

        send(
            recipients=self.recipients,
            sender=sender,
            subject=self.subject,
            message=self.message,
            reference_doctype=self.doctype,
            reference_name=self.name,
            unsubscribe_method=
            "/api/method/erpnext.crm.doctype.newsletter.newsletter.unsubscribe",
            unsubscribe_params={"name": self.newsletter_list},
            bulk_priority=0)

        if not frappe.flags.in_test:
            frappe.db.auto_commit_on_many_writes = False
Example #4
0
	def test_bulk(self, send_after=None):
		from frappe.email.bulk import send
		send(recipients = ['*****@*****.**', '*****@*****.**'],
			sender="*****@*****.**",
			reference_doctype='User', reference_name='Administrator',
			subject='Testing Bulk', message='This is a bulk mail!', send_after=send_after)

		bulk = frappe.db.sql("""select * from `tabBulk Email` where status='Not Sent'""", as_dict=1)
		self.assertEquals(len(bulk), 2)
		self.assertTrue('*****@*****.**' in [d['recipient'] for d in bulk])
		self.assertTrue('*****@*****.**' in [d['recipient'] for d in bulk])
		self.assertTrue('Unsubscribe' in bulk[0]['message'])
Example #5
0
def add_comment(args=None):
	"""
		args = {
			'comment': '',
			'comment_by': '',
			'comment_by_fullname': '',
			'comment_doctype': '',
			'comment_docname': '',
			'page_name': '',
		}
	"""

	if not args:
		args = frappe.local.form_dict
	args['doctype'] = "Comment"

	page_name = args.get("page_name")
	if "page_name" in args:
		del args["page_name"]
	if "cmd" in args:
		del args["cmd"]

	comment = frappe.get_doc(args)
	comment.flags.ignore_permissions = True
	comment.insert()

	# since comments are embedded in the page, clear the web cache
	clear_cache(page_name)

	# notify commentors
	commentors = [d[0] for d in frappe.db.sql("""select comment_by from tabComment where
		comment_doctype=%s and comment_docname=%s and
		ifnull(unsubscribed, 0)=0""", (comment.comment_doctype, comment.comment_docname))]

	owner = frappe.db.get_value(comment.comment_doctype, comment.comment_docname, "owner")
	recipients = list(set(commentors if owner=="Administrator" else (commentors + [owner])))

	message = _("{0} by {1}").format(markdown2.markdown(args.get("comment")), comment.comment_by_fullname)
	message += "<p><a href='{0}/{1}' style='font-size: 80%'>{2}</a></p>".format(frappe.utils.get_request_site_address(),
		page_name, _("View it in your browser"))

	from frappe.email.bulk import send

	send(recipients=recipients,
		doctype='Comment',
		email_field='comment_by',
		subject = _("New comment on {0} {1}").format(comment.comment_doctype, comment.comment_docname),
		message = message,
		ref_doctype=comment.comment_doctype, ref_docname=comment.comment_docname)

	template = frappe.get_template("templates/includes/comments/comment.html")

	return template.render({"comment": comment.as_dict()})
Example #6
0
def add_comment(args=None):
	"""
		args = {
			'comment': '',
			'comment_by': '',
			'comment_by_fullname': '',
			'comment_doctype': '',
			'comment_docname': '',
			'page_name': '',
		}
	"""

	if not args:
		args = frappe.local.form_dict
	args['doctype'] = "Comment"

	page_name = args.get("page_name")
	if "page_name" in args:
		del args["page_name"]
	if "cmd" in args:
		del args["cmd"]

	comment = frappe.get_doc(args)
	comment.comment_type = "Comment"
	comment.flags.ignore_permissions = True
	comment.insert()

	# since comments are embedded in the page, clear the web cache
	clear_cache(page_name)

	# notify commentors
	commentors = [d[0] for d in frappe.db.sql("""select comment_by from tabComment where
		comment_doctype=%s and comment_docname=%s and
		ifnull(unsubscribed, 0)=0""", (comment.comment_doctype, comment.comment_docname))]

	owner = frappe.db.get_value(comment.comment_doctype, comment.comment_docname, "owner")
	recipients = list(set(commentors if owner=="Administrator" else (commentors + [owner])))

	message = _("{0} by {1}").format(markdown2.markdown(args.get("comment")), comment.comment_by_fullname)
	message += "<p><a href='{0}/{1}' style='font-size: 80%'>{2}</a></p>".format(frappe.utils.get_request_site_address(),
		page_name, _("View it in your browser"))

	from frappe.email.bulk import send

	send(recipients=recipients,
		subject = _("New comment on {0} {1}").format(comment.comment_doctype, comment.comment_docname),
		message = message,
		reference_doctype=comment.comment_doctype, reference_name=comment.comment_docname)

	template = frappe.get_template("templates/includes/comments/comment.html")

	return template.render({"comment": comment.as_dict()})
Example #7
0
def add_comment(args=None):
	"""
		args = {
			'comment': '',
			'comment_by': '',
			'comment_by_fullname': '',
			'reference_doctype': '',
			'reference_name': '',
			'page_name': '',
		}
	"""

	if not args:
		args = frappe.local.form_dict

	page_name = args.get("page_name")

	doc = frappe.get_doc(args["reference_doctype"], args["reference_name"])
	comment = doc.add_comment("Comment", args["comment"], comment_by=args["comment_by"])
	comment.flags.ignore_permissions = True
	comment.sender_full_name = args["comment_by_fullname"]
	comment.save()

	# since comments are embedded in the page, clear the web cache
	clear_cache(page_name)

	# notify commentors
	commentors = [d[0] for d in frappe.db.sql("""select sender from `tabCommunication`
		where
			communication_type = 'Comment' and comment_type = 'Comment'
			and reference_doctype=%s
			and reference_name=%s""", (comment.reference_doctype, comment.reference_name))]

	owner = frappe.db.get_value(doc.doctype, doc.name, "owner")
	recipients = list(set(commentors if owner=="Administrator" else (commentors + [owner])))

	message = _("{0} by {1}").format(markdown2.markdown(args.get("comment")), comment.sender_full_name)
	message += "<p><a href='{0}/{1}' style='font-size: 80%'>{2}</a></p>".format(frappe.utils.get_request_site_address(),
		page_name, _("View it in your browser"))

	from frappe.email.bulk import send

	send(recipients=recipients,
		subject = _("New comment on {0} {1}").format(doc.doctype, doc.name),
		message = message,
		reference_doctype=doc.doctype, reference_name=doc.name)

	template = frappe.get_template("templates/includes/comments/comment.html")

	return template.render({"comment": comment.as_dict()})
Example #8
0
def add_comment(args=None):
	"""
		args = {
			'comment': '',
			'comment_by': '',
			'comment_by_fullname': '',
			'reference_doctype': '',
			'reference_name': '',
			'page_name': '',
		}
	"""

	if not args:
		args = frappe.local.form_dict

	page_name = args.get("page_name")

	doc = frappe.get_doc(args["reference_doctype"], args["reference_name"])
	comment = doc.add_comment("Comment", args["comment"], comment_by=args["comment_by"])
	comment.flags.ignore_permissions = True
	comment.sender_full_name = args["comment_by_fullname"]
	comment.save()

	# since comments are embedded in the page, clear the web cache
	clear_cache(page_name)

	# notify commentors
	commentors = [d[0] for d in frappe.db.sql("""select sender from `tabCommunication`
		where
			communication_type = 'Comment' and comment_type = 'Comment'
			and reference_doctype=%s
			and reference_name=%s""", (comment.reference_doctype, comment.reference_name))]

	owner = frappe.db.get_value(doc.doctype, doc.name, "owner")
	recipients = list(set(commentors if owner=="Administrator" else (commentors + [owner])))

	message = _("{0} by {1}").format(frappe.utils.markdown(args.get("comment")), comment.sender_full_name)
	message += "<p><a href='{0}/{1}' style='font-size: 80%'>{2}</a></p>".format(frappe.utils.get_request_site_address(),
		page_name, _("View it in your browser"))

	from frappe.email.bulk import send

	send(recipients=recipients,
		subject = _("New comment on {0} {1}").format(doc.doctype, doc.name),
		message = message,
		reference_doctype=doc.doctype, reference_name=doc.name)

	template = frappe.get_template("templates/includes/comments/comment.html")

	return template.render({"comment": comment.as_dict()})
    def test_bulk(self):
        from frappe.email.bulk import send
        send(recipients=['*****@*****.**', '*****@*****.**'],
             sender="*****@*****.**",
             doctype='User',
             email_field='email',
             subject='Testing Bulk',
             message='This is a bulk mail!')

        bulk = frappe.db.sql(
            """select * from `tabBulk Email` where status='Not Sent'""",
            as_dict=1)
        self.assertEquals(len(bulk), 2)
        self.assertTrue('*****@*****.**' in [d['recipient'] for d in bulk])
        self.assertTrue('*****@*****.**' in [d['recipient'] for d in bulk])
        self.assertTrue('Unsubscribe' in bulk[0]['message'])
Example #10
0
	def test_unsubscribe(self):
		from frappe.email.bulk import unsubscribe, send
		unsubscribe(doctype="User", name="Administrator", email="*****@*****.**")

		self.assertTrue(frappe.db.get_value("Email Unsubscribe",
			{"reference_doctype": "User", "reference_name": "Administrator", "email": "*****@*****.**"}))

		send(recipients = ['*****@*****.**', '*****@*****.**'],
			sender="*****@*****.**",
			reference_doctype='User', reference_name= "Administrator",
			subject='Testing Bulk', message='This is a bulk mail!')

		bulk = frappe.db.sql("""select * from `tabBulk Email` where status='Not Sent'""",
			as_dict=1)
		self.assertEquals(len(bulk), 1)
		self.assertFalse('*****@*****.**' in [d['recipient'] for d in bulk])
		self.assertTrue('*****@*****.**' in [d['recipient'] for d in bulk])
		self.assertTrue('Unsubscribe' in bulk[0]['message'])
Example #11
0
	def send_bulk(self):
		if not self.get("recipients"):
			# in case it is called via worker
			self.recipients = self.get_recipients()

		self.validate_send()

		sender = self.send_from or frappe.utils.get_formatted_email(self.owner)

		from frappe.email.bulk import send

		if not frappe.flags.in_test:
			frappe.db.auto_commit_on_many_writes = True

		send(recipients = self.recipients, sender = sender,
			subject = self.subject, message = self.message,
			doctype = self.send_to_doctype, email_field = self.get("email_field") or "email_id",
			ref_doctype = self.doctype, ref_docname = self.name)

		if not frappe.flags.in_test:
			frappe.db.auto_commit_on_many_writes = False
	def send_bulk(self):
		if not self.get("recipients"):
			# in case it is called via worker
			self.recipients = self.get_recipients()

		self.validate_send()

		sender = self.send_from or frappe.utils.get_formatted_email(self.owner)

		if not frappe.flags.in_test:
			frappe.db.auto_commit_on_many_writes = True

		send(recipients = self.recipients, sender = sender,
			subject = self.subject, message = self.message,
			reference_doctype = self.doctype, reference_name = self.name,
			unsubscribe_method = "/api/method/erpnext.crm.doctype.newsletter.newsletter.unsubscribe",
			unsubscribe_params = {"name": self.newsletter_list},
			bulk_priority = 0)

		if not frappe.flags.in_test:
			frappe.db.auto_commit_on_many_writes = False