def test_outgoing(self): frappe.flags.sent_mail = None make(subject = "test-mail-000", content="test mail 000", recipients="*****@*****.**", send_email=True, sender="*****@*****.**") mail = email.message_from_string(frappe.get_last_doc("Bulk Email").message) self.assertTrue("test-mail-000" in mail.get("Subject"))
def send_individual_statement(customer, email_id, company, from_date, to_date): data = get_report_content( company, customer, from_date=from_date, to_date=to_date, ) # Get PDF Data pdf_data = get_pdf(data) if not pdf_data: return attachments = [{"fname": get_file_name(), "fcontent": pdf_data}] if email_id == "to_find": email_id = frappe.get_value("Customer", customer, "email_id") make( recipients=email_id, send_email=True, subject="Customer Statement from {0}".format(company), content= "Good day. <br> Please find attached your latest statement from {0}". format(company), attachments=attachments, doctype="Report", name="General Ledger", )
def test_print_format(self): make(sender="*****@*****.**", recipients="*****@*****.**", content="test mail 001", subject="test-mail-002", doctype="Email Account", name="_Test Email Account 1", print_format="Standard", send_email=True) sent_mail = email.message_from_string(frappe.get_last_doc("Email Queue").message) self.assertTrue("test-mail-002" in sent_mail.get("Subject"))
def post_referrals(): user = check_permissions() full_name, addresses = frappe.form_dict.get( 'fullName'), frappe.form_dict.get('email_addresses') sub = "You are invited to CapitalVia by {0}".format(full_name) msg = """Hello! <br> Congratulations! you have been refereed by {0}. <br> To start using CapitalVia's Service signup here - https://www.capitalvia.com/offers""".format( full_name) make(content=msg, subject=sub, sender="*****@*****.**", sender_full_name=full_name, recipients=addresses, communication_medium="Email", send_email=True) frappe.publish_realtime(event="new_notifications", message={ "type": "default", "message": "Thank you for your referrals." }, user=frappe.session.user) frappe.db.commit() return "Success"
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 = frappe.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 = frappe.render_template(auto_repeat_doc.message, {'doc': new_rv}) attachments = [ frappe.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)
def sendClusterTarget(year, month): doc = frappe.get_all("Cluster Business Plan", filters={ "year": year, "month": month }, fields=["name"]) #return doc if len(doc) == 0: frappe.throw("No Target Set For This Month") count = 0 cc = frappe.db.get_value("Cluster Business Plan Setting", "Cluster Business Plan Setting", "email_cc_in_daily") subject = 'Business Plan For ' + str(month) + '-' + str(year) print_format = 'Cluster Plan' print_letterhead = 0 for row in doc: clster_data = frappe.get_doc("Cluster Business Plan", row.name) #getClusterData(clster_data.employee_code,year,month,row.name) receipient = getUserIdfromEmployeeCode(clster_data.employee_code) make(recipients=receipient, cc=cc, subject=subject, doctype='Cluster Business Plan', name=row.name, send_email=1, print_format=print_format, print_letterhead=int(print_letterhead)) count = count + 1 return count
def send_mail(entry, email_campaign): if email_campaign.email_campaign_for == "Email Group": recipients = frappe.get_all( "Email Group Member", {"email_group": email_campaign.get("recipient")}, "email") recipient = [d.email for d in recipients] else: recipient = [ frappe.db.get_value(email_campaign.email_campaign_for, email_campaign.get("recipient"), 'email_id') ] email_template = frappe.get_doc("Email Template", entry.get("email_template")) sender = frappe.db.get_value("User", email_campaign.get("sender"), 'email') context = { "doc": frappe.get_doc(email_campaign.email_campaign_for, email_campaign.recipient) } for email in recipient: make(doctype="Email Campaign", name=email_campaign.name, subject=frappe.render_template(email_template.get("subject"), context), content=frappe.render_template(email_template.get("response"), context), sender=sender, recipients=email, communication_medium="Email", sent_or_received="Sent", send_email=True, email_template=email_template.name)
def getAllClusterDocumnetMonthly(): d = datetime.date.today() year = d.strftime("%Y") month = d.strftime("%B") doc = frappe.get_all("Cluster Business Plan", filters={ "year": year, "month": month }, fields=["name"]) count = 0 for row in doc: clster_data = frappe.get_doc("Cluster Business Plan", row.name) getClusterData(clster_data.employee_code, year, month, row.name) receipient = getUserIdfromEmployeeCode(clster_data.employee_code) make( recipients=receipient, cc='[email protected],[email protected]', subject='Monthly Cluster Business Plan', doctype='Cluster Business Plan', name=row.name, send_email=1, print_format='Cluster Business Print', print_letterhead=1) count = count + 1 return count
def make_email_queue(email_queue): name_list = [] for key, data in email_queue.items(): name = frappe.db.get_value('Sales Invoice', {'offline_pos_name': key}, 'name') data = json.loads(data) sender = frappe.session.user print_format = "POS Invoice" attachments = [ frappe.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
def send_notification(self, new_doc): """Notify concerned people about recurring document generation""" subject = self.subject or '' message = self.message or '' if not self.subject: subject = _("New {0}: {1}").format(new_doc.doctype, new_doc.name) elif "{" in self.subject: subject = frappe.render_template(self.subject, {'doc': new_doc}) if not self.message: message = _("Please find attached {0}: {1}").format( new_doc.doctype, new_doc.name) elif "{" in self.message: message = frappe.render_template(self.message, {'doc': new_doc}) print_format = self.print_format or 'Standard' attachments = [ frappe.attach_print(new_doc.doctype, new_doc.name, file_name=new_doc.name, print_format=print_format) ] recipients = self.recipients.split('\n') make(doctype=new_doc.doctype, name=new_doc.name, recipients=recipients, subject=subject, content=message, attachments=attachments, send_email=1)
def sendBDETarget(year, month): doc = frappe.get_all("BDE Target and Incentive Plan", filters={ "year": year, "month": month }, fields=["name"]) if len(doc) == 0: frappe.throw("No Target Set For This Month") #return doc count = 0 cc = '*****@*****.**' subject = 'Business Plan For ' + str(month) + '-' + str(year) print_format = "BDE Target" #print_letterhead= frappe.db.get_value("Cluster Business Plan Setting","Cluster Business Plan Setting","print_letterhead") for row in doc: bde_data = frappe.get_doc("BDE Target and Incentive Plan", row.name) receipient = getUserIdfromEmployeeCode(bde_data.employee_code) make(recipients=receipient, cc=cc, subject=subject, doctype='BDE Target and Incentive Plan', name=row.name, send_email=1, print_format=print_format, print_letterhead=0) count = count + 1 return count
def send_email(self, data, sender, subject, message, attachments): make(subject=subject, content=message, recipients=data.email_id, sender=sender, attachments=attachments, send_email=True)["name"] frappe.msgprint(_("Email sent to supplier {0}").format(data.supplier))
def test_outgoing(self): make(subject="test-mail-000", content="test mail 000", recipients="*****@*****.**", send_email=True, sender="*****@*****.**") mail = email.message_from_string( frappe.get_last_doc("Email Queue").message) self.assertTrue("test-mail-000" in mail.get("Subject"))
def send_email(self, email, sender, subject, message, attachments): make(subject=subject, content=message, recipients=email, sender=sender, attachments=attachments, send_email=True, doctype=self.doctype, name=self.name)["name"] frappe.msgprint(_("Email sent to suppliers"))
def send_email(self, data, sender, subject, message, attachments): make( subject=subject, content=message, recipients=data.email_id, sender=sender, attachments=attachments, send_email=True, )["name"] frappe.msgprint(_("Email sent to supplier {0}").format(data.supplier))
def send_notification(self, new_doc): """Notify concerned people about recurring document generation""" subject = self.subject or '' message = self.message or '' if not self.subject: subject = _("New {0}: {1}").format(new_doc.doctype, new_doc.name) elif "{" in self.subject: subject = frappe.render_template(self.subject, {'doc': new_doc}) print_format = self.print_format or 'Standard' error_string = None try: attachments = [ frappe.attach_print(new_doc.doctype, new_doc.name, file_name=new_doc.name, print_format=print_format) ] except frappe.PermissionError: error_string = _( "A recurring {0} {1} has been created for you via Auto Repeat {2}." ).format(new_doc.doctype, new_doc.name, self.name) error_string += "<br><br>" error_string += _( "{0}: Failed to attach new recurring document. To enable attaching document in the auto repeat notification email, enable {1} in Print Settings" ).format(frappe.bold(_('Note')), frappe.bold(_('Allow Print for Draft'))) attachments = '[]' if error_string: message = error_string elif not self.message: message = _("Please find attached {0}: {1}").format( new_doc.doctype, new_doc.name) elif "{" in self.message: message = frappe.render_template(self.message, {'doc': new_doc}) recipients = self.recipients.split('\n') make(doctype=new_doc.doctype, name=new_doc.name, recipients=recipients, subject=subject, content=message, attachments=attachments, send_email=1)
def make_email_queue(email_queue): name_list = [] for key, data in email_queue.items(): name = frappe.db.get_value('Sales Invoice', {'offline_pos_name': key}, 'name') data = json.loads(data) sender = frappe.session.user print_format = "POS Invoice" attachments = [frappe.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
def test_threading(self): frappe.db.sql("""delete from tabCommunication where sender in ('*****@*****.**', '*****@*****.**')""") # send sent_name = make(subject = "Test", content="test content", recipients="*****@*****.**", sender="*****@*****.**", send_email=True)["name"] sent_mail = email.message_from_string(frappe.get_last_doc("Bulk Email").message) with open(os.path.join(os.path.dirname(__file__), "test_mails", "reply-1.raw"), "r") as f: raw = f.read() raw = raw.replace("<-- in-reply-to -->", sent_mail.get("Message-Id")) test_mails = [raw] # parse reply email_account = frappe.get_doc("Email Account", "_Test Email Account 1") email_account.receive(test_mails=test_mails) sent = frappe.get_doc("Communication", sent_name) comm = frappe.get_doc("Communication", {"sender": "*****@*****.**"}) self.assertEquals(comm.reference_doctype, sent.doctype) self.assertEquals(comm.reference_name, sent.name)
def send_mail(entry, email_campaign): recipient = frappe.db.get_value(email_campaign.email_campaign_for, email_campaign.get("recipient"), 'email_id') email_template = frappe.get_doc("Email Template", entry.get("email_template")) sender = frappe.db.get_value("User", email_campaign.get("sender"), 'email') context = { "doc": frappe.get_doc(email_campaign.email_campaign_for, email_campaign.recipient) } # send mail and link communication to document comm = make(doctype="Email Campaign", name=email_campaign.name, subject=frappe.render_template(email_template.get("subject"), context), content=frappe.render_template(email_template.get("response"), context), sender=sender, recipients=recipient, communication_medium="Email", sent_or_received="Sent", send_email=True, email_template=email_template.name) return comm
def test_threading(self): cleanup(["in", ['*****@*****.**', '*****@*****.**']]) # send sent_name = make(subject="Test", content="test content", recipients="*****@*****.**", sender="*****@*****.**", doctype="ToDo", name=frappe.get_last_doc("ToDo").name, send_email=True)["name"] sent_mail = email.message_from_string( frappe.get_last_doc("Email Queue").message) with open( os.path.join(os.path.dirname(__file__), "test_mails", "reply-1.raw"), "r") as f: raw = f.read() raw = raw.replace("<-- in-reply-to -->", sent_mail.get("Message-Id")) test_mails = [raw] # parse reply email_account = frappe.get_doc("Email Account", "_Test Email Account 1") email_account.receive(test_mails=test_mails) sent = frappe.get_doc("Communication", sent_name) comm = frappe.get_doc("Communication", {"sender": "*****@*****.**"}) self.assertEqual(comm.reference_doctype, sent.reference_doctype) self.assertEqual(comm.reference_name, sent.reference_name)
def send_mail(entry, email_campaign): recipient_list = [] if email_campaign.email_campaign_for == "Email Group": for member in frappe.db.get_list( "Email Group Member", filters={"email_group": email_campaign.get("recipient")}, fields=["email"]): recipient_list.append(member['email']) else: recipient_list.append( frappe.db.get_value(email_campaign.email_campaign_for, email_campaign.get("recipient"), "email_id")) email_template = frappe.get_doc("Email Template", entry.get("email_template")) sender = frappe.db.get_value("User", email_campaign.get("sender"), "email") context = { "doc": frappe.get_doc(email_campaign.email_campaign_for, email_campaign.recipient) } # send mail and link communication to document comm = make(doctype="Email Campaign", name=email_campaign.name, subject=frappe.render_template(email_template.get("subject"), context), content=frappe.render_template(email_template.get("response"), context), sender=sender, recipients=recipient_list, communication_medium="Email", sent_or_received="Sent", send_email=True, email_template=email_template.name) return comm
def getAllClusterDocumnetDaily(): d = datetime.date.today() year = d.strftime("%Y") month = d.strftime("%B") #return (year,month) doc = frappe.get_all("Cluster Business Plan", filters={ "year": year, "month": month }, fields=["name"]) #return doc count = 0 cc = frappe.db.get_value("Cluster Business Plan Setting", "Cluster Business Plan Setting", "email_cc_in_daily") subject = frappe.db.get_value("Cluster Business Plan Setting", "Cluster Business Plan Setting", "daily_email_subject") print_format = frappe.db.get_value("Cluster Business Plan Setting", "Cluster Business Plan Setting", "daily_print_format_name") print_letterhead = frappe.db.get_value("Cluster Business Plan Setting", "Cluster Business Plan Setting", "print_letterhead") for row in doc: clster_data = frappe.get_doc("Cluster Business Plan", row.name) getClusterData(clster_data.employee_code, year, month, row.name) receipient = getUserIdfromEmployeeCode(clster_data.employee_code) make(recipients=receipient, cc=cc, subject=subject, doctype='Cluster Business Plan', name=row.name, send_email=1, print_format=print_format, print_letterhead=int(print_letterhead)) count = count + 1 return count
def post_ticket(): user = check_permissions() full_name, sub, msg = frappe.form_dict.get( 'fullName'), frappe.form_dict.get('subject'), frappe.form_dict.get( 'message') make(content=msg, subject=sub, sender="*****@*****.**", sender_full_name=full_name, recipients="*****@*****.**", communication_medium="Email", send_email=True) frappe.publish_realtime( event="new_notifications", message={ "type": "default", "message": "Your ticket is posted and will soon be reflected here." }, user=frappe.session.user) return "Success"
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 = frappe.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 = frappe.render_template(auto_repeat_doc.message, {'doc': new_rv}) attachments = [frappe.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)
def DailyReport(): d = datetime.date.today() year = d.strftime("%Y") month = d.strftime("%B") #return (year,month) doc=frappe.get_all("NBM Cluster Business Plan",filters={"year":year,"month":month},fields=["name"]) #return doc count=0 cc= frappe.db.get_value("NBM Cluster Business Plan Setting","NBM Cluster Business Plan Setting", "email_cc_in_daily") subject= frappe.db.get_value("NBM Cluster Business Plan Setting","NBM Cluster Business Plan Setting","daily_email_subject") print_format= frappe.db.get_value("NBM Cluster Business Plan Setting","NBM Cluster Business Plan Setting","daily_print_format_name") print_letterhead= frappe.db.get_value("NBM Cluster Business Plan Setting","NBM Cluster Business Plan Setting","print_letterhead") to= frappe.db.get_value("NBM Cluster Business Plan Setting","NBM Cluster Business Plan Setting","to") for row in doc: clster_data=frappe.get_doc("NBM Cluster Business Plan",row.name) getClusterData() receipient=to make(recipients=receipient,cc=cc,subject=subject,content=generate_multiPDF(),doctype='NBM Cluster Business Plan',name=row.name,send_email=1,print_format=print_format,print_letterhead=int(print_letterhead)) count=count+1 return count
def passport_validate_check(): from frappe.core.doctype.communication.email import make frappe.flags.sent_mail = None emp = frappe.db.sql( "select name,valid_upto,user_id,passport_notification from `tabEmployee`" ) for i in emp: if i[1] and i[3]: date_difference = date_diff(i[1], getdate(nowdate())) if date_difference <= 30 and date_difference > 0: content_msg_emp = "Your Passport validity will end after {0} days".format( date_difference) prefered_email = frappe.get_value("Employee", filters={"name": i[0]}, fieldname="prefered_email") if prefered_email: try: sent = 0 make(subject="Passport Validity Notification", content=content_msg_emp, recipients=prefered_email, send_email=True, sender="*****@*****.**") sent = 1 print('send email for ' + prefered_email) except: frappe.msgprint("could not send") print(content_msg_emp) print( '----------------------------------------------------------------' )
def send_statements(company=None, manual=None): """ Send out customer statements """ from csf_tz.custom_api import print_out show_progress = manual progress_title = _("Sending customer statements...") if show_progress: publish_progress(percent=0, title=progress_title) if company is None: company = frappe.db.get_single_value('Customer Statements Sender', 'company') if not company: frappe.throw( _('Company field is required on Customer Statements Sender')) exit() from_date_for_all_customers = frappe.db.get_single_value( 'Customer Statements Sender', 'from_date_for_all_customers') to_date_for_all_customers = frappe.db.get_single_value( 'Customer Statements Sender', 'to_date_for_all_customers') email_list = get_recipient_list() idx = 0 total = len(email_list) for row in email_list: idx += 1 if row.email_id is not None and row.email_id != "": if row.send_statement == "Yes": if show_progress: publish_progress( percent=(idx / total * 100), title=progress_title, description=' Creating PDF for {0}'.format( row.customer)) data = get_report_content( company, row.customer, from_date=from_date_for_all_customers, to_date=to_date_for_all_customers) # Get PDF Data pdf_data = get_pdf(data) if not pdf_data: return attachments = [{ 'fname': get_file_name(), 'fcontent': pdf_data }] make( recipients=row.email_id, send_email=True, subject='Customer Statement from {0}'.format(company), content= 'Good day. <br> Please find attached your latest statement from {0}' .format(company), attachments=attachments, doctype="Report", name="General Ledger") if show_progress: publish_progress(percent=100, title=progress_title) frappe.msgprint('Emails queued for sending')