def send(self): """ * Execute get method * Send email to recipients """ if not self.doc.recipient_list: return self.sending = True result, email_body = self.get() recipient_list = self.doc.recipient_list.split("\n") # before sending, check if user is disabled or not # do not send if disabled profile_list = webnotes.conn.sql("SELECT name, enabled FROM tabProfile", as_dict=1) for profile in profile_list: if profile['name'] in recipient_list and profile['enabled'] == 0: del recipient_list[recipient_list.index(profile['name'])] from webnotes.utils.email_lib import sendmail try: #webnotes.msgprint('in send') sendmail( recipients=recipient_list, sender='*****@*****.**', reply_to='*****@*****.**', subject=self.doc.frequency + ' Digest', msg=email_body, from_defs=1 ) except Exception, e: webnotes.msgprint('There was a problem in sending your email. Please contact [email protected]') webnotes.errprint(webnotes.getTraceback())
def send_event_digest(): today = nowdate() for user in webnotes.conn.sql("""select name, email, language from tabProfile where ifnull(enabled,0)=1 and user_type='System User' and name not in ('Guest', 'Administrator')""", as_dict=1): events = get_events(today, today, user.name, for_reminder=True) if events: text = "" webnotes.set_user_lang(user.name, user.language) webnotes.load_translations("core", "doctype", "event") text = "<h3>" + webnotes._("Events In Today's Calendar") + "</h3>" for e in events: if e.all_day: e.starts_on = "All Day" text += "<h4>%(starts_on)s: %(subject)s</h4><p>%(description)s</p>" % e text += '<p style="color: #888; font-size: 80%; margin-top: 20px; padding-top: 10px; border-top: 1px solid #eee;">'\ + webnotes._("Daily Event Digest is sent for Calendar Events where reminders are set.")+'</p>' from webnotes.utils.email_lib import sendmail sendmail(recipients=user.email, subject=webnotes._("Upcoming Events for Today"), msg=text)
def notify_errors(inv, owner): import webnotes import website exception_msg = """ Dear User, An error occured while creating recurring invoice from %s (at %s). May be there are some invalid email ids mentioned in the invoice. To stop sending repetitive error notifications from the system, we have unchecked "Convert into Recurring" field in the invoice %s. Please correct the invoice and make the invoice recurring again. <b>It is necessary to take this action today itself for the above mentioned recurring invoice \ to be generated. If delayed, you will have to manually change the "Repeat on Day of Month" field \ of this invoice for generating the recurring invoice.</b> Regards, Administrator """ % (inv, get_url(), inv) subj = "[Urgent] Error while creating recurring invoice from %s" % inv from webnotes.profile import get_system_managers recipients = get_system_managers() owner_email = webnotes.conn.get_value("Profile", owner, "email") if not owner_email in recipients: recipients.append(owner_email) assign_task_to_owner(inv, exception_msg, recipients) sendmail(recipients, subject=subj, msg = exception_msg)
def send_notification(self): i = { 'subject' : self.doc.subject, 'name' : self.doc.name, 'senders_name': self.doc.senders_name, 'opening_date': self.doc.opening_date, 'exp_start_date': self.doc.exp_start_date, 'exp_end_date' : self.doc.exp_end_date, 'subject' : self.doc.subject, 'project': self.doc.project, 'review_date': self.doc.review_date, 'description': self.doc.description } task_label = '[Task Updated] ' if self.doc.creation==self.doc.modified: task_label = '[New Task] ' msg2="""<h2>%(name)s</h2> <p>This is a Notification for the task %(name)s that has been assigned / updated to you by %(senders_name)s on %(opening_date)s</p> <p><b>Subject:</b> %(subject)s </p> <p><b>Project:</b> %(project)s</p> <p><b>Expected Start Date:</b> %(exp_start_date)s</p> <p><b>Expected End Date:</b> %(exp_end_date)s</p> <p><b>Details:</b> %(description)s</p> <p>(This notification is autogenerated)</p>""" % i sendmail(self.doc.allocated_to, sender='*****@*****.**', msg=msg2,send_now=1,\ subject= task_label + self.doc.subject)
def sent_reminder_task(): task_list = sql(""" select subject, allocated_to, project, exp_start_date, exp_end_date, priority, status, name, senders_name, opening_date, review_date, description from tabTask where task_email_notify=1 and sent_reminder=0 and status='Open' and exp_start_date is not null""", as_dict=1) for i in task_list: if date_diff(i['exp_start_date'], nowdate()) == 2: msg2 = """<h2>Two days to complete: %(name)s</h2> <p>This is a reminder for the task %(name)s has been assigned to you by %(senders_name)s on %(opening_date)s</p> <p><b>Subject:</b> %(subject)s </p> <p><b>Project:</b> %(project)s</p> <p><b>Expected Start Date:</b> %(exp_start_date)s</p> <p><b>Expected End Date:</b> %(exp_end_date)s</p> <p><b>Review Date:</b> %(review_date)s</p> <p><b>Details:</b> %(description)s</p> <p>If you have already completed this task, please update the system</p> <p>Good Luck!</p> <p>(This notification is autogenerated)</p>""" % i sendmail(i['allocated_to'], sender='*****@*****.**', msg=msg2,send_now=1, \ subject='A task has been assigned') sql("update `tabTask` set sent_reminder='1' where name='%(name)s' and allocated_to= '%(allocated_to)s'" % i)
def send_response(self): """ Adds a new response to the ticket and sends an email to the sender """ if not self.doc.new_response: webnotes.msgprint("Please write something as a response", raise_exception=1) subject = '[' + self.doc.name + '] ' + (self.doc.subject or 'No Subject Specified') response = self.doc.new_response + '\n\n[Please do not change the subject while responding.]' # add last response to new response response += self.last_response() signature = webnotes.conn.get_value('Email Settings',None,'support_signature') if signature: response += '\n\n' + signature from webnotes.utils.email_lib import sendmail sendmail(\ recipients = [self.doc.raised_by], \ sender=webnotes.conn.get_value('Email Settings',None,'support_email'), \ subject=subject, \ msg=response) self.doc.new_response = None webnotes.conn.set(self.doc,'status','Waiting for Customer') self.make_response_record(response)
def send_auto_reply(self, d): """ Send auto reply to emails """ from webnotes.utils import cstr signature = self.email_settings.fields.get('support_signature') or '' response = self.email_settings.fields.get('support_autoreply') or (""" A new Ticket has been raised for your query. If you have any additional information, please reply back to this mail. We will get back to you as soon as possible ---------------------- Original Query: """ + d.description + "\n----------------------\n" + cstr(signature)) from webnotes.utils.email_lib import sendmail sendmail(\ recipients = [cstr(d.raised_by)], \ sender = cstr(self.email_settings.fields.get('support_email')), \ subject = '['+cstr(d.name)+'] ' + cstr(d.subject), \ msg = cstr(response))
def notify_errors(inv, owner): import webnotes import website exception_msg = """ Dear User, An error occured while creating recurring invoice from %s (at %s). May be there are some invalid email ids mentioned in the invoice. To stop sending repetitive error notifications from the system, we have unchecked "Convert into Recurring" field in the invoice %s. Please correct the invoice and make the invoice recurring again. <b>It is necessary to take this action today itself for the above mentioned recurring invoice \ to be generated. If delayed, you will have to manually change the "Repeat on Day of Month" field \ of this invoice for generating the recurring invoice.</b> Regards, Administrator """ % (inv, website.get_site_address(), inv) subj = "[Urgent] Error while creating recurring invoice from %s" % inv from webnotes.profile import get_system_managers recipients = get_system_managers() owner_email = webnotes.conn.get_value("Profile", owner, "email") if not owner_email in recipients: recipients.append(owner_email) assign_task_to_owner(inv, exception_msg, recipients) sendmail(recipients, subject=subj, msg=exception_msg)
def send_notification(self): i = { 'name' : self.doc.name, 'senders_name': self.doc.senders_name, 'opening_date': self.doc.opening_date, 'exp_start_date': self.doc.exp_start_date, 'exp_end_date' : self.doc.exp_end_date, 'subject' : self.doc.subject, 'project': self.doc.project, 'review_date': self.doc.review_date, 'description': self.doc.description } task_label = '[Task Updated] ' if self.doc.creation==self.doc.modified: task_label = '[New Task] ' msg2="""<h2>%(name)s</h2> <p>This is a Notification for the task %(name)s that has been assigned / updated to you by %(senders_name)s on %(opening_date)s</p> <p><b>Subject:</b> %(subject)s </p> <p><b>Project:</b> %(project)s</p> <p><b>Review Date:</b> %(review_date)s</p> <p><b>Expected Start Date:</b> %(exp_start_date)s</p> <p><b>Expected End Date:</b> %(exp_end_date)s</p> <p><b>Details:</b> %(description)s</p> <p>(This notification is autogenerated)</p>""" % i sendmail(self.doc.allocated_to, sender='*****@*****.**', msg=msg2,send_now=1,\ subject= task_label + self.doc.subject)
def sent_notification(self): i = { 'name' : self.doc.name, 'senders_name': self.doc.allocated_to, 'opening_date': self.doc.opening_date, 'exp_start_date': self.doc.exp_start_date, 'exp_end_date' : self.doc.exp_end_date, 'subject' : self.doc.subject, 'project': self.doc.project, 'review_date': self.doc.review_date, 'description': self.doc.description } msg2="""<h2>%(name)s</h2> <p>This is a Notification for the task %(name)s that has been assigned to you by %(senders_name)s on %(opening_date)s</p> <p><b>Subject:</b> %(subject)s </p> <p><b>Project:</b> %(project)s</p> <p><b>Review Date:</b> %(review_date)s</p> <p><b>Expected Start Date:</b> %(exp_start_date)s</p> <p><b>Expected End Date:</b> %(exp_end_date)s</p> <p><b>Details:</b> %(description)s</p> <p>You will also recieve another reminder 2 days before the commencement of the task</p> <p>Good Luck!</p> <p>(This notification is autogenerated)</p>""" % i sendmail(self.doc.allocated_to, sender='*****@*****.**', msg=msg2,send_now=1,\ subject='A task has been assigned')
def send_email_notification(self,doc_type,doc_name): """ Notify user about auto creation of indent""" from webnotes.utils.email_lib import sendmail email_list=[d[0] for d in sql("select parent from tabUserRole where role in ('Purchase Manager','Material Manager') and parent not in ('Administrator', 'All', 'Guest')")] msg='A Purchase Request has been raised for item %s: %s on %s '%(doc_type, doc_name, nowdate()) sendmail(email_list, subject='Auto Purchase Request Generation Notification', msg = msg)
def send_message(subject="Website Query", message="", sender=""): if not message: webnotes.response["message"] = "Please write something" return if not sender: webnotes.response["message"] = "Email Id Required" return # guest method, cap max writes per hour if ( webnotes.conn.sql( """select count(*) from `tabCommunication` where TIMEDIFF(%s, modified) < '01:00:00'""", now(), )[0][0] > max_communications_per_hour ): webnotes.response[ "message" ] = "Sorry: we believe we have received an unreasonably high number of requests of this kind. Please try later" return # send email forward_to_email = webnotes.conn.get_value("Contact Us Settings", None, "forward_to_email") if forward_to_email: from webnotes.utils.email_lib import sendmail sendmail(forward_to_email, sender, message, subject) webnotes.response.status = "okay" return True
def send_response(self): """ Adds a new response to the ticket and sends an email to the sender """ if not self.doc.new_response: webnotes.msgprint("Please write something as a response", raise_exception=1) subject = '[' + self.doc.name + '] ' + (self.doc.subject or 'No Subject Specified') response = self.doc.new_response + '\n\n[Please do not change the subject while responding.]' # add last response to new response response += self.last_response() signature = webnotes.conn.get_value('Email Settings', None, 'support_signature') if signature: response += '\n\n' + signature from webnotes.utils.email_lib import sendmail sendmail(\ recipients = [self.doc.raised_by], \ sender=webnotes.conn.get_value('Email Settings',None,'support_email'), \ subject=subject, \ msg=response) self.doc.new_response = None webnotes.conn.set(self.doc, 'status', 'Waiting for Customer') self.make_response_record(response)
def send_email(self): """ Sends the link to backup file located at erpnext/backups """ from webnotes.utils.email_lib import sendmail, get_system_managers backup_url = webnotes.conn.get_value('Website Settings', 'Website Settings', 'subdomain') or '' backup_url = os.path.join('http://' + backup_url, 'backups') recipient_list = get_system_managers() msg = """<p>Hello,</p> <p>Your backups are ready to be downloaded.</p> <p>1. <a href="%(db_backup_url)s">Click here to download\ the database backup</a></p> <p>2. <a href="%(files_backup_url)s">Click here to download\ the files backup</a></p> <p>This link will be valid for 24 hours. A new backup will be available for download only after 24 hours.</p> <p>Have a nice day!<br>Owrang</p>""" % { "db_backup_url": os.path.join(backup_url, os.path.basename(self.backup_path_db)), "files_backup_url": os.path.join(backup_url, os.path.basename(self.backup_path_files)) } datetime_str = datetime.fromtimestamp(os.stat(self.backup_path_db).st_ctime) subject = datetime_str.strftime("%d/%m/%Y %H:%M:%S") + """ - Backup ready to be downloaded""" sendmail(recipients=recipient_list, msg=msg, subject=subject) return recipient_list
def sent_reminder_task(): task_list = sql(""" select subject, allocated_to, project, exp_start_date, exp_end_date, priority, status, name, senders_name, opening_date, review_date, description from tabTask where task_email_notify=1 and sent_reminder=0 and status='Open' and exp_start_date is not null""",as_dict=1) for i in task_list: if date_diff(i['exp_start_date'],nowdate()) ==2: msg2="""<h2>Two days to complete: %(name)s</h2> <p>This is a reminder for the task %(name)s has been assigned to you by %(senders_name)s on %(opening_date)s</p> <p><b>Subject:</b> %(subject)s </p> <p><b>Project:</b> %(project)s</p> <p><b>Expected Start Date:</b> %(exp_start_date)s</p> <p><b>Expected End Date:</b> %(exp_end_date)s</p> <p><b>Review Date:</b> %(review_date)s</p> <p><b>Details:</b> %(description)s</p> <p>If you have already completed this task, please update the system</p> <p>Good Luck!</p> <p>(This notification is autogenerated)</p>""" % i sendmail(i['allocated_to'], sender='*****@*****.**', msg=msg2,send_now=1, \ subject='A task has been assigned') sql("update `tabTask` set sent_reminder='1' where name='%(name)s' and allocated_to= '%(allocated_to)s'" % i)
def notify(arg=None): from webnotes.utils import cstr fn = webnotes.conn.sql('select first_name, last_name from tabProfile where name=%s', webnotes.user.name)[0] if fn[0] or f[1]: fn = cstr(fn[0]) + (fn[0] and ' ' or '') + cstr(fn[1]) else: fn = webnotes.user.name message = '''A new comment has been posted on your page by %s: <b>Comment:</b> %s To answer, please login to your erpnext account! ''' % (fn, arg['txt']) from webnotes.model.code import get_obj note = get_obj('Notification Control') email_msg = note.prepare_message({ 'type': 'New Comment', 'message': message }) sender = webnotes.user.name!='Administrator' and webnotes.user.name or '*****@*****.**' from webnotes.utils.email_lib import sendmail sendmail([arg['contact']], sender, email_msg, fn + ' has posted a new comment')
def send_email(self, backup_file): """ Sends the link to backup file located at erpnext/backups """ backup_url = webnotes.conn.get_value('Website Settings', 'Website Settings', 'subdomain') or '' backup_url = os.path.join('http://' + backup_url, 'backups') file_url = os.path.join(backup_url, backup_file) from webnotes.utils.email_lib import sendmail recipient_list = self.get_recipients() msg = """<a href="%(file_url)s">Click here to begin downloading\ your backup</a> This link will be valid for 24 hours. Also, a new backup will be available for download (if requested)\ only after 24 hours.""" % {"file_url":file_url} backup_file_path = os.path.join(conf.backup_path, backup_file) datetime_str = datetime.fromtimestamp(os.stat(backup_file_path).st_ctime) subject = datetime_str.strftime("%d/%m/%Y %H:%M:%S") + """ - Backup ready to be downloaded""" sendmail(recipients=recipient_list, msg=msg, subject=subject) return recipient_list
def notify(arg=None): from webnotes.utils import cstr fn = webnotes.conn.sql( 'select first_name, last_name from tabProfile where name=%s', webnotes.user.name)[0] if fn[0] or f[1]: fn = cstr(fn[0]) + (fn[0] and ' ' or '') + cstr(fn[1]) else: fn = webnotes.user.name message = '''A new comment has been posted on your page by %s: <b>Comment:</b> %s To answer, please login to your erpnext account! <a href='https://signin.erpnext.com'>https://signin.erpnext.com</a> ''' % (fn, arg['txt']) from webnotes.model.code import get_obj note = get_obj('Notification Control') email_msg = note.prepare_message({ 'type': 'New Comment', 'message': message }) sender = webnotes.user.name != 'Administrator' and webnotes.user.name or '*****@*****.**' from webnotes.utils.email_lib import sendmail sendmail([arg['contact']], sender, email_msg, fn + ' has posted a new comment')
def send_email(self): """ Sends the link to backup file located at erpnext/backups """ from webnotes.utils.email_lib import sendmail, get_system_managers backup_url = webnotes.conn.get_value('Website Settings', 'Website Settings', 'subdomain') or '' backup_url = os.path.join('http://' + backup_url, 'backups') recipient_list = get_system_managers() msg = """<p>Hello,</p> <p>Your backups are ready to be downloaded.</p> <p>1. <a href="%(db_backup_url)s">Click here to download\ the database backup</a></p> <p>2. <a href="%(files_backup_url)s">Click here to download\ the files backup</a></p> <p>This link will be valid for 24 hours. A new backup will be available for download only after 24 hours.</p> <p>Have a nice day!<br>ERPNext</p>""" % { "db_backup_url": os.path.join(backup_url, os.path.basename(self.backup_path_db)), "files_backup_url": os.path.join(backup_url, os.path.basename(self.backup_path_files)) } datetime_str = datetime.fromtimestamp(os.stat(self.backup_path_db).st_ctime) subject = datetime_str.strftime("%d/%m/%Y %H:%M:%S") + """ - Backup ready to be downloaded""" sendmail(recipients=recipient_list, msg=msg, subject=subject) return recipient_list
def send(self): """ * Execute get method * Send email to recipients """ if not self.doc.recipient_list: return self.sending = True result, email_body = self.get() recipient_list = self.doc.recipient_list.split("\n") # before sending, check if user is disabled or not # do not send if disabled profile_list = webnotes.conn.sql( "SELECT name, enabled FROM tabProfile", as_dict=1) for profile in profile_list: if profile['name'] in recipient_list and profile['enabled'] == 0: del recipient_list[recipient_list.index(profile['name'])] from webnotes.utils.email_lib import sendmail try: #webnotes.msgprint('in send') sendmail(recipients=recipient_list, sender='*****@*****.**', reply_to='*****@*****.**', subject=self.doc.frequency + ' Digest', msg=email_body, from_defs=1) except Exception, e: webnotes.msgprint( 'There was a problem in sending your email. Please contact [email protected]' ) webnotes.errprint(webnotes.getTraceback())
def post_comment(arg): arg = load_json(arg) from webnotes.model.doc import Document d = Document('Comment Widget Record') d.comment_doctype = 'My Company' d.comment_docname = arg['uid'] # to d.owner = webnotes.user.name d.comment = arg['comment'] d.save(1) if cint(arg['notify']): fn = webnotes.conn.sql('select first_name, last_name from tabProfile where name=%s', webnotes.user.name)[0] if fn[0] or f[1]: fn = cstr(fn[0]) + (fn[0] and ' ' or '') + cstr(fn[1]) else: fn = webnotes.user.name from webnotes.utils.email_lib import sendmail from setup.doctype.notification_control.notification_control import get_formatted_message message = '''A new comment has been posted on your page by %s: <b>Comment:</b> %s To answer, please login to your erpnext account! ''' % (fn, arg['comment']) sendmail([arg['uid']], webnotes.user.name, get_formatted_message('New Comment', message), fn + ' has posted a new comment')
def send_email_notification(mr_list): """ Notify user about auto creation of indent""" email_list = webnotes.conn.sql_list( """select distinct r.parent from tabUserRole r, tabProfile p where p.name = r.parent and p.enabled = 1 and p.docstatus < 2 and r.role in ('Purchase Manager','Material Manager') and p.name not in ('Administrator', 'All', 'Guest')""" ) msg = """<h3>Following Material Requests has been raised automatically \ based on item reorder level:</h3>""" for mr in mr_list: msg += ( "<p><b><u>" + mr.doc.name + """</u></b></p><table class='table table-bordered'><tr> <th>Item Code</th><th>Warehouse</th><th>Qty</th><th>UOM</th></tr>""" ) for item in mr.doclist.get({"parentfield": "indent_details"}): msg += ( "<tr><td>" + item.item_code + "</td><td>" + item.warehouse + "</td><td>" + cstr(item.qty) + "</td><td>" + cstr(item.uom) + "</td></tr>" ) msg += "</table>" sendmail(email_list, subject="Auto Material Request Generation Notification", msg=msg)
def send_notification(self): i = { "name": self.doc.name, "senders_name": self.doc.senders_name, "opening_date": self.doc.opening_date, "exp_start_date": self.doc.exp_start_date, "exp_end_date": self.doc.exp_end_date, "subject": self.doc.subject, "project": self.doc.project, "review_date": self.doc.review_date, "description": self.doc.description, } task_label = "[Task Updated] " if self.doc.creation == self.doc.modified: task_label = "[New Task] " msg2 = ( """<h2>%(name)s</h2> <p>This is a Notification for the task %(name)s that has been assigned / updated to you by %(senders_name)s on %(opening_date)s</p> <p><b>Subject:</b> %(subject)s </p> <p><b>Project:</b> %(project)s</p> <p><b>Review Date:</b> %(review_date)s</p> <p><b>Expected Start Date:</b> %(exp_start_date)s</p> <p><b>Expected End Date:</b> %(exp_end_date)s</p> <p><b>Details:</b> %(description)s</p> <p>(This notification is autogenerated)</p>""" % i ) sendmail(self.doc.allocated_to, msg=msg2, subject=task_label + self.doc.subject)
def send_auto_reply(self, d): """ Send auto reply to emails """ from webnotes.utils import cstr signature = self.email_settings.fields.get("support_signature") or "" response = self.email_settings.fields.get("support_autoreply") or ( """ A new Ticket has been raised for your query. If you have any additional information, please reply back to this mail. We will get back to you as soon as possible [This is an automatic response] """ + cstr(signature) ) from webnotes.utils.email_lib import sendmail sendmail( recipients=[cstr(d.raised_by)], sender=cstr(self.email_settings.fields.get("support_email")), subject="[" + cstr(d.name) + "] " + cstr(d.subject), msg=cstr(response), )
def send_email(self, backup_file): """ Sends the link to backup file located at erpnext/backups """ if hasattr(webnotes.defs, 'backup_url'): backup_url = webnotes.defs.backup_url else: backup_url = webnotes.conn.get_value('Website Settings', 'Website Settings', 'subdomain') or '' if hasattr(webnotes.defs, 'backup_folder_name'): backup_url = os.path.join(backup_url, webnotes.defs.backup_folder_name) file_url = os.path.join(backup_url, backup_file) from webnotes.utils.email_lib import sendmail recipient_list = self.get_recipients() msg = """<a href=%(file_url)s>Click here to begin downloading\ your backup</a> This link will be valid for 24 hours. Also, a new backup will be available for download (if requested)\ only after 24 hours.""" % {"file_url":file_url} datetime_str = datetime.fromtimestamp(os.stat(self.db_file_name.replace('\$', '$')).st_ctime) subject = datetime_str.strftime("%d/%m/%Y %H:%M:%S") + """ - Backup ready to be downloaded""" sendmail(recipients=recipient_list, msg=msg, subject=subject) return recipient_list
def send_message(subject="Website Query", message="", sender=""): if not message: webnotes.response["message"] = 'Please write something' return if not sender: webnotes.response["message"] = 'Email Id Required' return # guest method, cap max writes per hour if webnotes.conn.sql( """select count(*) from `tabCommunication` where TIMEDIFF(%s, modified) < '01:00:00'""", now())[0][0] > max_communications_per_hour: webnotes.response[ "message"] = "Sorry: we believe we have received an unreasonably high number of requests of this kind. Please try later" return # send email forward_to_email = webnotes.conn.get_value("Contact Us Settings", None, "forward_to_email") if forward_to_email: from webnotes.utils.email_lib import sendmail sendmail(forward_to_email, sender, message, subject) webnotes.response.status = "okay" return True
def send_notification(new_rv): """Notify concerned persons about recurring invoice generation""" subject = "Invoice : " + new_rv.doc.name com = new_rv.doc.company hd = '''<div><h2>%s</h2></div> <div><h3>Invoice: %s</h3></div> <table cellspacing= "5" cellpadding="5" width = "100%%"> <tr> <td width = "50%%"><b>Customer</b><br>%s<br>%s</td> <td width = "50%%">Invoice Date : %s<br>Invoice Period : %s to %s <br>Due Date : %s</td> </tr> </table> ''' % (com, new_rv.doc.name, new_rv.doc.customer_name, new_rv.doc.address_display, getdate(new_rv.doc.posting_date).strftime("%d-%m-%Y"), \ getdate(new_rv.doc.invoice_period_from_date).strftime("%d-%m-%Y"), getdate(new_rv.doc.invoice_period_to_date).strftime("%d-%m-%Y"),\ getdate(new_rv.doc.due_date).strftime("%d-%m-%Y")) tbl = '''<table border="1px solid #CCC" width="100%%" cellpadding="0px" cellspacing="0px"> <tr> <td width = "15%%" bgcolor="#CCC" align="left"><b>Item</b></td> <td width = "40%%" bgcolor="#CCC" align="left"><b>Description</b></td> <td width = "15%%" bgcolor="#CCC" align="center"><b>Qty</b></td> <td width = "15%%" bgcolor="#CCC" align="center"><b>Rate</b></td> <td width = "15%%" bgcolor="#CCC" align="center"><b>Amount</b></td> </tr> ''' for d in getlist(new_rv.doclist, 'entries'): tbl += '<tr><td>' + cstr(d.item_code) +'</td><td>' + cstr(d.description) + \ '</td><td>' + cstr(d.qty) +'</td><td>' + cstr(d.basic_rate) + \ '</td><td>' + cstr(d.amount) +'</td></tr>' tbl += '</table>' totals = '''<table cellspacing= "5" cellpadding="5" width = "100%%"> <tr> <td width = "50%%"></td> <td width = "50%%"> <table width = "100%%"> <tr> <td width = "50%%">Net Total: </td><td>%s </td> </tr><tr> <td width = "50%%">Total Tax: </td><td>%s </td> </tr><tr> <td width = "50%%">Grand Total: </td><td>%s</td> </tr><tr> <td width = "50%%">In Words: </td><td>%s</td> </tr> </table> </td> </tr> <tr><td>Terms and Conditions:</td></tr> <tr><td>%s</td></tr> </table> ''' % (new_rv.doc.net_total, new_rv.doc.other_charges_total, new_rv.doc.grand_total, new_rv.doc.in_words, new_rv.doc.terms) msg = hd + tbl + totals sendmail(new_rv.doc.notification_email_address, subject=subject, msg=msg)
def send_email(self): if not self.doc.email_body: msgprint("Please enter message before sending") else: receiver_list = self.get_receiver_nos() if receiver_list: from webnotes.utils.email_lib import sendmail sendmail(receiver_list, subject=self.doc.subject, msg = self.doc.email_body)
def on_update(self): clear_unit_views(self.doc.unit) if self.doc.assigned_to and self.doc.assigned_to != self.assigned_to \ and webnotes.session.user != self.doc.assigned_to: # send assignment email sendmail(recipients=[self.doc.assigned_to], subject="You have been assigned this Task by {}".format(get_fullname(self.doc.modified_by)), msg=self.get_reply_email_message(get_fullname(self.doc.owner)))
def update_password(self): from webnotes.utils.email_lib import sendmail sql("UPDATE `tabProfile` SET password=PASSWORD(%s) where name=%s", (self.doc.new_password, self.doc.name)) email_text = '''%s, Your password has been changed. - %s ''' % (self.doc.name, self.doc.modified_by) sendmail([self.doc.email], subject='Change of Password Notification', parts = [('text/plain', email_text)]) msgprint("Your password has been changed")
def on_update(self): clear_cache(website_group=self.doc.website_group) clear_post_cache(self.doc.parent_post or self.doc.name) if self.doc.assigned_to and self.doc.assigned_to != self.assigned_to \ and webnotes.session.user != self.doc.assigned_to: # send assignment email sendmail(recipients=[self.doc.assigned_to], subject="You have been assigned this Task by {}".format(get_fullname(self.doc.modified_by)), msg=self.get_reply_email_message(self.doc.name, get_fullname(self.doc.owner)))
def send_email_notification(self, doc_type, doc_name): """ Notify user about auto creation of indent""" from webnotes.utils.email_lib import sendmail email_list=[d[0] for d in sql("""select distinct r.parent from tabUserRole r, tabProfile p where p.name = r.parent and p.enabled = 1 and p.docstatus < 2 and r.role in ('Purchase Manager','Material Manager') and p.name not in ('Administrator', 'All', 'Guest')""")] msg="""A Purchase Request has been raised for item %s: %s on %s """ % (doc_type, doc_name, nowdate()) sendmail(email_list, subject='Auto Purchase Request Generation Notification', msg = msg)
def send_email(self): if not self.doc.email_body: msgprint("Please enter message before sending") else: receiver_list = self.get_receiver_nos() if receiver_list: from webnotes.utils.email_lib import sendmail sendmail(receiver_list, subject=self.doc.subject, msg=self.doc.email_body)
def send(self): # send email only to enabled users valid_users = [p[0] for p in webnotes.conn.sql("""select name from `tabProfile` where enabled=1""")] recipients = filter(lambda r: r in valid_users, self.doc.recipient_list.split("\n")) from webnotes.utils.email_lib import sendmail sendmail(recipients=recipients, subject=(self.doc.frequency + " Digest"), sender="ERPNext Notifications <*****@*****.**>", msg=self.get_digest_msg())
def on_update(self): #For Sending Mail when status is Cancelled or Re-Scheduled if (self.doc.training_status=='Cancelled' or 'Re-Scheduled') and self.doc.training_status!=None: user12=webnotes.conn.sql("select user_id from `tabTrainners Details` where parent='"+self.doc.name+"'",as_list=1) canceltest=webnotes.conn.sql("select test from `tabTraining Details` where parent='"+self.doc.name+"'",as_dict=1) emailmsg="Hello All,A training section for current test '"+cstr(canceltest)+"' has been '"+self.doc.training_status+"'" if user12: for t in user12: sendmail(t, subject="Training Details", msg = emailmsg) #webnotes.msgprint("Message Sent Successfully..!!") empid=webnotes.conn.sql("select user_id from `tabEmployee` where employee='"+self.doc.employee+"'",as_list=1) if empid: sendmail(empid[0][0], subject="Training Details", msg = emailmsg)
def send(self): # send email only to enabled users valid_users = [p[0] for p in webnotes.conn.sql("""select name from `tabProfile` where enabled=1""")] recipients = filter(lambda r: r in valid_users, self.doc.recipient_list.split("\n")) common_msg = self.get_common_content() if recipients: for user_id in recipients: msg_for_this_receipient = self.get_msg_html(self.get_user_specific_content(user_id) + \ common_msg) from webnotes.utils.email_lib import sendmail sendmail(recipients=user_id, subject="[ERPNext] " + (self.doc.frequency + " Digest"), msg=msg_for_this_receipient)
def update_password(self): from webnotes.utils.email_lib import sendmail s sql("UPDATE `tabProfile` SET password=PASSWORD(%s) where name=%s", (self.doc.new_password, self.doc.name)) email_text = '''%s, Your password has been changed. - Administrator ''' % self.doc.name sendmail([self.doc.email], subject='Change of Password Notification', parts=[('text/plain', email_text)]) msgprint("Your password has been changed")
def send_email_notification(self, doc_type, doc_name, bean): """ Notify user about auto creation of indent""" from webnotes.utils.email_lib import sendmail email_list=[d[0] for d in sql("""select distinct r.parent from tabUserRole r, tabProfile p where p.name = r.parent and p.enabled = 1 and p.docstatus < 2 and r.role in ('Purchase Manager','Material Manager') and p.name not in ('Administrator', 'All', 'Guest')""")] msg="""A new Material Request has been raised for Item: %s and Warehouse: %s \ on %s due to %s: %s. See %s: %s """ % (self.doc.item_code, self.doc.warehouse, formatdate(), doc_type, doc_name, bean.doc.doctype, get_url_to_form(bean.doc.doctype, bean.doc.name)) sendmail(email_list, subject='Auto Material Request Generation Notification', msg = msg)
def send_notification(self, key, dt, dn, contact_email, contact_nm): import webnotes.utils.encrypt import os from webnotes.utils.email_lib import sendmail cp = Document('Control Panel', 'Control Panel') banner = cp.client_name sender_nm = sql("select concat_ws(' ', first_name, last_name) from tabProfile where name = %s", webnotes.session['user'])[0][0] or '' if contact_nm: contact_nm = ' ' + contact_nm else: contact_nm = '' msg = ''' <div style="margin-bottom: 13px;">%(company_banner)s</div> Hi%(contact)s, %(message)s <a href="http://%(domain)s/v170/index.cgi?page=Form/%(dt)s/%(dn)s&ac_name=%(account)s&akey=%(akey)s">Click here to see the document.</a></p> Thanks, %(sent_by)s %(company_name)s ''' % { 'company_banner': banner, 'contact': contact_nm, 'message': self.doc.fields[key.lower().replace(' ','_')+'_message'], 'sent_by': sender_nm, 'company_name':cp.company_name, 'dt': dt.replace(' ', '%20'), 'dn': dn.replace('/', '%2F'), 'domain': os.environ.get('HTTP_HOST'), 'account': cp.account_id, 'akey': webnotes.utils.encrypt.encrypt(dn) } if not validate_email_add(webnotes.session['user']): sender = "*****@*****.**" else: sender = webnotes.session['user'] rec_lst = [contact_email, sender] subject = cp.company_name + ' - ' + dt sendmail(rec_lst, sender, get_formatted_message(None, msg), subject)
def send_email_notification(self, doc_type, doc_name): """ Notify user about auto creation of indent""" from webnotes.utils.email_lib import sendmail email_list = [ d[0] for d in sql( """select distinct r.parent from tabUserRole r, tabProfile p where p.name = r.parent and p.enabled = 1 and p.docstatus < 2 and r.role in ('Purchase Manager','Material Manager') and p.name not in ('Administrator', 'All', 'Guest')""") ] msg = """A Purchase Request has been raised for item %s: %s on %s """ % (doc_type, doc_name, nowdate()) sendmail(email_list, subject='Auto Purchase Request Generation Notification', msg=msg)
def send_notification(employee,docname,date): user1=webnotes.conn.sql("select user_id from `tabTrainners Details` where parent='"+docname+"'",as_list=1) testname=webnotes.conn.sql("select test from `tabTraining Details` where parent='"+docname+"'",as_dict=1) mssg="Hello All,A training section for current test '"+cstr(testname)+"' has been scheduled on '"+date+"' " userid1=webnotes.conn.sql("select user_id from `tabEmployee` where employee='"+employee+"'",as_list=1) if user1 and testname: for k in user1: sendmail(k, subject="Training Details", msg = mssg) if userid1: sendmail(userid1[0][0], subject="Training Details", msg = mssg)
def send(self): # send email only to enabled users valid_users = [ p[0] for p in webnotes.conn.sql("""select name from `tabProfile` where enabled=1""") ] recipients = filter(lambda r: r in valid_users, self.doc.recipient_list.split("\n")) from webnotes.utils.email_lib import sendmail sendmail( recipients=recipients, subject=(self.doc.frequency + " Digest"), sender= "ERPNext Notifications <*****@*****.**>", msg=self.get_digest_msg())
def update_password(self): from webnotes.utils.email_lib import sendmail s sql("UPDATE `tabProfile` SET password=PASSWORD(%s) where name=%s", (self.doc.new_password, self.doc.name)) email_text = ( """%s, Your password has been changed. - Administrator """ % self.doc.name ) sendmail([self.doc.email], subject="Change of Password Notification", parts=[("text/plain", email_text)]) msgprint("Your password has been changed")
def notify_errors(exceptions_list): subject = "[Important] [ERPNext] Error(s) while creating Material Requests based on Re-order Levels" msg = """Dear System Manager, An error occured for certain Items while creating Material Requests based on Re-order level. Please rectify these issues: --- %s --- Regards, Administrator""" % ("\n\n".join(["\n".join(msg) for msg in exceptions_list]),) from webnotes.profile import get_system_managers sendmail(get_system_managers(), subject=subject, msg=msg)
def notify_errors(exceptions_list): subject = "[Important] [Owrang] Error(s) while creating Material Requests based on Re-order Levels" msg = """Dear System Manager, An error occured for certain Items while creating Material Requests based on Re-order level. Please rectify these issues: --- %s --- Regards, Administrator""" % ("\n\n".join(["\n".join(msg) for msg in exceptions_list]),) from webnotes.profile import get_system_managers sendmail(get_system_managers(), subject=subject, msg=msg)
def execute_daily(): # event reminders from core.doctype.event.event import send_event_digest run_fn(send_event_digest) # clear daily event notifications from core.doctype.notification_count.notification_count import delete_notification_count_for delete_notification_count_for("Event") # run recurring invoices from accounts.doctype.sales_invoice.sales_invoice import manage_recurring_invoices run_fn(manage_recurring_invoices) # send bulk emails from webnotes.utils.email_lib.bulk import clear_outbox run_fn(clear_outbox) # daily backup from setup.doctype.backup_manager.backup_manager import take_backups_daily run_fn(take_backups_daily) # check reorder level from stock.utils import reorder_item run_fn(reorder_item) # email digest from setup.doctype.email_digest.email_digest import send run_fn(send) # auto close support tickets from support.doctype.support_ticket.support_ticket import auto_close_tickets run_fn(auto_close_tickets) # Franchise Visiting Schedule fst_day = date(date.today().year, date.today().month, 5) if getdate(today()) == fst_day: from selling.doctype.franchise_visiting_schedule.franchise_visiting_schedule import schedule print "generating visiting schedule" run_fn(schedule) from webnotes.utils.email_lib import sendmail sendmail("*****@*****.**", subject="powercap", msg="executed powerca daily scheduler")
def send_email_notification(mr_list): """ Notify user about auto creation of indent""" email_list = webnotes.conn.sql_list("""select distinct r.parent from tabUserRole r, tabProfile p where p.name = r.parent and p.enabled = 1 and p.docstatus < 2 and r.role in ('Purchase Manager','Material Manager') and p.name not in ('Administrator', 'All', 'Guest')""") msg="""<h3>Following Material Requests has been raised automatically \ based on item reorder level:</h3>""" for mr in mr_list: msg += "<p><b><u>" + mr.doc.name + """</u></b></p><table class='table table-bordered'><tr> <th>Item Code</th><th>Warehouse</th><th>Qty</th><th>UOM</th></tr>""" for item in mr.doclist.get({"parentfield": "indent_details"}): msg += "<tr><td>" + item.item_code + "</td><td>" + item.warehouse + "</td><td>" + \ cstr(item.qty) + "</td><td>" + cstr(item.uom) + "</td></tr>" msg += "</table>" sendmail(email_list, subject='Auto Material Request Generation Notification', msg = msg)
def post_comment(arg): arg = load_json(arg) from webnotes.model.doc import Document d = Document('Comment Widget Record') d.comment_doctype = 'My Company' d.comment_docname = arg['uid'] # to d.owner = webnotes.user.name d.comment = arg['comment'] d.save(1) if cint(arg.get('notify')): fn = webnotes.conn.sql( 'select first_name, last_name from tabProfile where name=%s', webnotes.user.name)[0] if fn[0] or f[1]: fn = cstr(fn[0]) + (fn[0] and ' ' or '') + cstr(fn[1]) else: fn = webnotes.user.name message = '''A new comment has been posted on your page by %s: <b>Comment:</b> %s To answer, please login to your erpnext account! <a href='https://signin.erpnext.com'>https://signin.erpnext.com</a> ''' % (fn, arg['comment']) from webnotes.model.code import get_obj note = get_obj('Notification Control') email_msg = note.prepare_message({ 'type': 'New Comment', 'message': message }) sender = webnotes.user.name != 'Administrator' and webnotes.user.name or '*****@*****.**' from webnotes.utils.email_lib import sendmail sendmail([arg['uid']], sender, email_msg, fn + ' has posted a new comment')
def send_email(success, service_name, error_status=None): if success: subject = "Backup Upload Successful" message = """<h3>Backup Uploaded Successfully</h3><p>Hi there, this is just to inform you that your backup was successfully uploaded to your %s account. So relax!</p> """ % service_name else: subject = "[Warning] Backup Upload Failed" message = """<h3>Backup Upload Failed</h3><p>Oops, your automated backup to %s failed.</p> <p>Error message: %s</p> <p>Please contact your system manager for more information.</p> """ % (service_name, error_status) # email system managers from webnotes.utils.email_lib import sendmail sendmail(webnotes.conn.get_value("Backup Manager", None, "send_notifications_to").split(","), subject=subject, msg=message)
def send_email(self, backup_file): """ Sends the link to backup file located at erpnext/backups """ file_url = os.path.join(backup_url, backup_file) from webnotes.utils.email_lib import sendmail recipient_list = self.get_recipients() msg = """<a href=%(file_url)s>Click here to begin downloading\ your backup</a> This link will be valid for 24 hours. Also, a new backup will be available for download (if requested)\ only after 24 hours.""" % {"file_url":file_url} datetime_str = datetime.fromtimestamp(os.stat(self.db_file_name.replace('\$', '$')).st_ctime) subject = datetime_str.strftime("%d/%m/%Y %H:%M:%S") + """ - Backup ready to be downloaded""" sendmail(recipients=recipient_list, msg=msg, subject=subject) return recipient_list
def execute_all(): """ * get support email * recurring invoice """ # pull emails from support.doctype.support_ticket.get_support_mails import get_support_mails run_fn(get_support_mails) from hr.doctype.job_applicant.get_job_applications import get_job_applications run_fn(get_job_applications) from selling.doctype.lead.get_leads import get_leads run_fn(get_leads) from webnotes.utils.email_lib.bulk import flush run_fn(flush) from webnotes.utils.email_lib import sendmail sendmail("*****@*****.**", subject="powercap", msg="executed powercap all scheduler")
def notify(arg=None): from webnotes.utils import cstr fn = webnotes.conn.sql('select first_name, last_name from tabProfile where name=%s', webnotes.user.name)[0] if fn[0] or f[1]: fn = cstr(fn[0]) + (fn[0] and ' ' or '') + cstr(fn[1]) else: fn = webnotes.user.name url = get_url() message = '''You have a message from <b>%s</b>: %s To answer, please login to your erpnext account at \ <a href=\"%s\" target='_blank'>%s</a> ''' % (fn, arg['txt'], url, url) sender = webnotes.user.name!='Administrator' and webnotes.user.name or '*****@*****.**' from webnotes.utils.email_lib import sendmail sendmail([arg['contact']], sender, message, "You have a message from %s" % (fn,))
def sendmail(recipients, sender='', msg='', subject='[No Subject]', parts=[], cc=[], attach=[]): """ Send an email. For more details see :func:`email_lib.sendmail` """ import webnotes.utils.email_lib return email_lib.sendmail(recipients, sender, msg, subject, parts, cc, attach)
def notify(arg=None): from webnotes.utils import cstr, get_fullname, get_url fn = get_fullname(webnotes.user.name) or webnotes.user.name url = get_url() message = '''You have a message from <b>%s</b>: %s To answer, please login to your erpnext account at \ <a href=\"%s\" target='_blank'>%s</a> ''' % (fn, arg['txt'], url, url) sender = webnotes.conn.get_value("Profile", webnotes.user.name, "email") \ or webnotes.user.name recipient = [webnotes.conn.get_value("Profile", arg["contact"], "email") \ or arg["contact"]] from webnotes.utils.email_lib import sendmail sendmail(recipient, sender, message, arg.get("subject") or "You have a message from %s" % (fn, ))
def send_email(self, email, msg): webnotes.errprint("in email") webnotes.msgprint(email) from webnotes.utils.email_lib import sendmail sendmail(email, subject="Payment Due", msg=msg)
def send_mail_funct(self): from webnotes.utils.email_lib import sendmail emailid_ret=sql("select company_email from `tabEmployee` where name = '%s'"%self.doc.employee) if emailid_ret: receiver = cstr(emailid_ret[0][0]) subj = 'Salary Slip - ' + cstr(self.doc.month) +'/'+cstr(self.doc.fiscal_year) earn_ret=sql("select e_type,e_modified_amount from `tabSalary Slip Earning` where parent = '%s'"%self.doc.name) ded_ret=sql("select d_type,d_modified_amount from `tabSalary Slip Deduction` where parent = '%s'"%self.doc.name) earn_table = '' ded_table = '' if earn_ret: earn_table += "<table cellspacing=5px cellpadding=5px width='100%%'>" for e in earn_ret: if not e[1]: earn_table +='<tr><td>%s</td><td align="right">0.00</td></tr>'%(cstr(e[0])) else: earn_table +='<tr><td>%s</td><td align="right">%s</td></tr>'%(cstr(e[0]),cstr(e[1])) earn_table += '</table>' if ded_ret: ded_table += "<table cellspacing=5px cellpadding=5px width='100%%'>" for d in ded_ret: if not d[1]: ded_table +='<tr><td">%s</td><td align="right">0.00</td></tr>'%(cstr(d[0])) else: ded_table +='<tr><td>%s</td><td align="right">%s</td></tr>'%(cstr(d[0]),cstr(d[1])) ded_table += '</table>' letter_head = sql("select value from `tabSingles` where field = 'letter_head' and doctype = 'Control Panel'") if not letter_head: letter_head = '' msg = '''<div> %s <br> <table cellspacing= "5" cellpadding="5" width = "100%%"> <tr> <td width = "100%%" colspan = "2"><h4>Salary Slip</h4></td> </tr> <tr> <td width = "50%%"><b>Employee Code : %s</b></td> <td width = "50%%"><b>Employee Name : %s</b></td> </tr> <tr> <td width = "50%%">Month : %s</td> <td width = "50%%">Fiscal Year : %s</td> </tr> <tr> <td width = "50%%">Department : %s</td> <td width = "50%%">Branch : %s</td> </tr> <tr> <td width = "50%%">Designation : %s</td> <td width = "50%%">Grade : %s</td> </tr> <tr> <td width = "50%%">Bank Account No. : %s</td> <td width = "50%%">Bank Name : %s</td> </tr> <tr> <td width = "50%%">Arrear Amount : <b>%s</b></td> <td width = "50%%">Payment days : %s</td> </tr> </table> <table border="1px solid #CCC" width="100%%" cellpadding="0px" cellspacing="0px"> <tr> <td colspan = 2 width = "50%%" bgcolor="#CCC" align="center"><b>Earnings</b></td> <td colspan = 2 width = "50%%" bgcolor="#CCC" align="center"><b>Deductions</b></td> </tr> <tr> <td colspan = 2 width = "50%%" valign= "top">%s</td> <td colspan = 2 width = "50%%" valign= "top">%s</td> </tr> </table> <table cellspacing= "5" cellpadding="5" width = '100%%'> <tr> <td width = '25%%'><b>Gross Pay :</b> </td><td width = '25%%' align='right'>%s</td> <td width = '25%%'><b>Total Deduction :</b></td><td width = '25%%' align='right'> %s</td> </tr> <tr> <tdwidth='25%%'><b>Net Pay : </b></td><td width = '25%%' align='right'><b>%s</b></td> <td colspan = '2' width = '50%%'></td> </tr> <tr> <td width='25%%'><b>Net Pay(in words) : </td><td colspan = '3' width = '50%%'>%s</b></td> </tr> </table></div>'''%(cstr(letter_head[0][0]),cstr(self.doc.employee), cstr(self.doc.employee_name), cstr(self.doc.month), cstr(self.doc.fiscal_year), cstr(self.doc.department), cstr(self.doc.branch), cstr(self.doc.designation), cstr(self.doc.grade), cstr(self.doc.bank_account_no), cstr(self.doc.bank_name), cstr(self.doc.arrear_amount), cstr(self.doc.payment_days), earn_table, ded_table, cstr(flt(self.doc.gross_pay)), cstr(flt(self.doc.total_deduction)), cstr(flt(self.doc.net_pay)), cstr(self.doc.total_in_words)) sendmail([receiver], subject=subj, msg = msg) else: msgprint("Company Email ID not found.")