def send_email(self): """ Sends the link to backup file located at erpnext/backups """ from webnotes.utils.email_lib import sendmail, get_system_managers recipient_list = get_system_managers() db_backup_url = get_url( os.path.join('backups', os.path.basename(self.backup_path_db))) files_backup_url = get_url( os.path.join('backups', os.path.basename(self.backup_path_files))) 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": db_backup_url, "files_backup_url": files_backup_url } 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_email(self): """ Sends the link to backup file located at erpnext/backups """ from webnotes.utils.email_lib import sendmail, get_system_managers recipient_list = get_system_managers() db_backup_url = get_url(os.path.join('backups', os.path.basename(self.backup_path_db))) files_backup_url = get_url(os.path.join('backups', os.path.basename(self.backup_path_files))) 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": db_backup_url, "files_backup_url": files_backup_url } 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 notify_errors(inv, owner): import webnotes 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 set_portal_link(sent_via, comm): """set portal link in footer""" from webnotes.webutils import is_portal_enabled, get_portal_links from webnotes.utils import get_url, cstr import urllib footer = None if is_portal_enabled(): portal_opts = get_portal_links().get(sent_via.doc.doctype) if portal_opts: valid_recipient = cstr(sent_via.doc.email or sent_via.doc.email_id or sent_via.doc.contact_email) in comm.recipients if not valid_recipient: attach_portal_link = False else: attach_portal_link = True if portal_opts.get("conditions"): for fieldname, val in portal_opts["conditions"].items(): if sent_via.doc.fields.get(fieldname) != val: attach_portal_link = False break if attach_portal_link: url = "%s/%s?name=%s" % (get_url(), portal_opts["page"], urllib.quote(sent_via.doc.name)) footer = """<!-- Portal Link --><hr> <a href="%s" target="_blank">View this on our website</a>""" % url return footer
def send_login_mail(self, subject, txt, add_args): """send mail with login details""" import os from webnotes.utils.email_lib import sendmail_md from webnotes.profile import get_user_fullname from webnotes.utils import get_url full_name = get_user_fullname(webnotes.session['user']) if full_name == "Guest": full_name = "Administrator" args = { 'first_name': self.doc.first_name or self.doc.last_name or "user", 'user': self.doc.name, 'company': webnotes.conn.get_default('company') or webnotes.get_config().get("app_name"), 'login_url': get_url(), 'product': webnotes.get_config().get("app_name"), 'user_fullname': full_name } args.update(add_args) sender = webnotes.session.user not in ("Administrator", "Guest") and webnotes.session.user or None if self.doc.email: sendmail_md(recipients=self.doc.email, sender=sender, subject=subject, msg=txt % args) elif self.doc.number: # webnotes.errprint(self.doc.number) # msgprint(get_obj('SMS Control', 'SMS Control').send_sms(self.doc.number, txt % args)) msg = txt % args self.send_sms(msg)
def send_login_mail(self, subject, template, add_args): """send mail with login details""" from webnotes.profile import get_user_fullname from webnotes.utils import get_url mail_titles = webnotes.get_hooks().get("login_mail_title", []) title = webnotes.conn.get_default('company') or (mail_titles and mail_titles[0]) or "" full_name = get_user_fullname(webnotes.session['user']) if full_name == "Guest": full_name = "Administrator" args = { 'first_name': self.doc.first_name or self.doc.last_name or "user", 'user': self.doc.name, 'title': title, 'login_url': get_url(), 'user_fullname': full_name } args.update(add_args) sender = webnotes.session.user not in ("Administrator", "Guest") and webnotes.session.user or None webnotes.sendmail(recipients=self.doc.email, sender=sender, subject=subject, message=webnotes.get_template(template).render(args))
def send_login_mail(self, subject, txt, add_args): """send mail with login details""" import os from webnotes.utils.email_lib import sendmail_md from webnotes.profile import get_user_fullname from webnotes.utils import get_url full_name = get_user_fullname(webnotes.session["user"]) if full_name == "Guest": full_name = "Administrator" args = { "first_name": self.doc.first_name or self.doc.last_name or "user", "user": self.doc.name, "company": webnotes.conn.get_default("company") or webnotes.get_config().get("app_name"), "login_url": get_url(), "product": webnotes.get_config().get("app_name"), "user_fullname": full_name, } args.update(add_args) sender = webnotes.session.user not in ("Administrator", "Guest") and webnotes.session.user or None sendmail_md(recipients=self.doc.email, sender=sender, subject=subject, msg=txt % args)
def reset_password(self): from webnotes.utils import random_string, get_url key = random_string(32) webnotes.conn.set_value("Profile", self.doc.name, "reset_password_key", key) self.password_reset_mail(get_url("/update-password?key=" + key))
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_login_mail(self, subject, txt, add_args): """send mail with login details""" import os from webnotes.utils.email_lib import sendmail_md from webnotes.profile import get_user_fullname from webnotes.utils import get_url full_name = get_user_fullname(webnotes.session['user']) if full_name == "Guest": full_name = "Administrator" args = { 'first_name': self.doc.first_name or self.doc.last_name or "user", 'user': self.doc.name, 'company': webnotes.conn.get_default('company') or webnotes.get_config().get("app_name"), 'login_url': get_url(), 'product': webnotes.get_config().get("app_name"), 'user_fullname': full_name } args.update(add_args) sender = webnotes.session.user not in ("Administrator", "Guest") and webnotes.session.user or None sendmail_md(recipients=self.doc.email, sender=sender, subject=subject, msg=txt % args)
def send_welcome_mail(self): """send welcome mail to user with password and login url""" from webnotes.utils import random_string, get_url self.doc.reset_password_key = random_string(32) link = get_url("/update-password?key=" + self.doc.reset_password_key) txt = """ ## %(company)s Dear %(first_name)s, A new account has been created for you. Your login id is: %(user)s To complete your registration, please click on the link below: <a href="%(link)s">%(link)s</a> Thank you,<br> %(user_fullname)s """ self.send_login_mail("Welcome to " + webnotes.get_config().get("app_name"), txt, { "link": link })
def send_welcome_mail(self): """send welcome mail to user with password and login url""" from webnotes.utils import random_string, get_url self.doc.reset_password_key = random_string(32) link = get_url("/update-password?key=" + self.doc.reset_password_key) txt = """ %(company)s Dear %(first_name)s, A new account has been created for you. Your login id is: %(user)s To complete your registration, please click on the link below: <a href="%(link)s">%(link)s</a> Thank you,<br> %(user_fullname)s """ self.send_login_mail("Welcome to MedSynaptic" , txt, { "link": link })
def send_welcome_mail(self): from webnotes.utils import random_string, get_url self.doc.reset_password_key = random_string(32) link = get_url("/update-password?key=" + self.doc.reset_password_key) self.send_login_mail("Verify Your Account", "templates/emails/new_user.html", {"link": link})
def notify(arg=None): from webnotes.utils import cstr, get_fullname, get_url webnotes.sendmail(\ recipients=[webnotes.conn.get_value("Profile", arg["contact"], "email") or arg["contact"]], sender= webnotes.conn.get_value("Profile", webnotes.session.user, "email"), subject="New Message from " + get_fullname(webnotes.user.name), message=webnotes.get_template("templates/emails/new_message.html").render({ "from": get_fullname(webnotes.user.name), "message": arg['txt'], "link": get_url() }) )
def report_errors(): from webnotes.utils.email_lib import sendmail_to_system_managers from webnotes.utils import get_url errors = [("""<p>Time: %(modified)s</p> <pre><code>%(error)s</code></pre>""" % d) for d in webnotes.conn.sql("""select modified, error from `tabScheduler Log` where DATEDIFF(NOW(), modified) < 1 and error not like '%%[Errno 110] Connection timed out%%' limit 10""", as_dict=True)] if errors: sendmail_to_system_managers("ERPNext Scheduler Failure Report", (""" <p>Dear System Managers,</p> <p>Reporting ERPNext failed scheduler events for the day (max 10):</p> <p>URL: <a href="%(url)s" target="_blank">%(url)s</a></p><hr>""" % {"url":get_url()}) + "<hr>".join(errors))
def update_message(doc): from webnotes.utils import get_url import urllib updated = message + """<div style="padding: 7px; border-top: 1px solid #aaa; margin-top: 17px;"> <small><a href="%s/?%s"> Unsubscribe</a> from this list.</small></div>""" % (get_url(), urllib.urlencode({ "cmd": "webnotes.utils.email_lib.bulk.unsubscribe", "email": doc.get(email_field), "type": doctype, "email_field": email_field })) return updated
def report_errors(): from webnotes.utils.email_lib import sendmail_to_system_managers from webnotes.utils import get_url errors = [("""<p>Time: %(modified)s</p> <pre><code>%(error)s</code></pre>""" % d) for d in webnotes.conn.sql("""select modified, error from `tabScheduler Log` where DATEDIFF(NOW(), modified) < 1 and error not like '%%[Errno 110] Connection timed out%%' limit 10""", as_dict=True)] if errors: sendmail_to_system_managers("Owrang Scheduler Failure Report", (""" <p>Dear System Managers,</p> <p>Reporting Owrang failed scheduler events for the day (max 10):</p> <p>URL: <a href="%(url)s" target="_blank">%(url)s</a></p><hr>""" % {"url":get_url()}) + "<hr>".join(errors))
def get_error_report(from_date=None, to_date=None, limit=10): from webnotes.utils import get_url, now_datetime, add_days if not from_date: from_date = add_days(now_datetime().date(), -1) if not to_date: to_date = add_days(now_datetime().date(), -1) errors = get_errors(from_date, to_date, limit) if errors: return 1, """<h4>Scheduler Failed Events (max {limit}):</h4> <p>URL: <a href="{url}" target="_blank">{url}</a></p><hr>{errors}""".format( limit=limit, url=get_url(), errors="<hr>".join(errors)) else: return 0, "<p>Scheduler didn't encounter any problems.</p>"
def set_portal_link(sent_via, comm): """set portal link in footer""" footer = None if is_signup_enabled() and hasattr(sent_via, "get_portal_page"): portal_page = sent_via.get_portal_page() if portal_page: is_valid_recipient = cstr(sent_via.doc.email or sent_via.doc.email_id or sent_via.doc.contact_email) in comm.recipients if is_valid_recipient: url = "%s/%s?name=%s" % (get_url(), portal_page, urllib.quote(sent_via.doc.name)) footer = """<!-- Portal Link --><hr> <a href="%s" target="_blank">View this on our website</a>""" % url return footer
def update_message(doc): from webnotes.utils import get_url import urllib updated = message + """<div style="padding: 7px; border-top: 1px solid #aaa; margin-top: 17px;"> <small><a href="%s/?%s"> Unsubscribe</a> from this list.</small></div>""" % ( get_url(), urllib.urlencode({ "cmd": "webnotes.utils.email_lib.bulk.unsubscribe", "email": doc.get(email_field), "type": doctype, "email_field": email_field })) return updated
def update_message(formatted, doc, add_unsubscribe_link): updated = formatted if add_unsubscribe_link: unsubscribe_link = """<div style="padding: 7px; border-top: 1px solid #aaa; margin-top: 17px;"> <small><a href="%s/?%s"> Unsubscribe</a> from this list.</small></div>""" % (get_url(), urllib.urlencode({ "cmd": "webnotes.utils.email_lib.bulk.unsubscribe", "email": doc.get(email_field), "type": doctype, "email_field": email_field })) updated = updated.replace("<!--unsubscribe link here-->", unsubscribe_link) return updated
def set_portal_link(sent_via, comm): """set portal link in footer""" from webnotes.webutils import is_signup_enabled from webnotes.utils import get_url, cstr import urllib footer = None if is_signup_enabled() and hasattr(sent_via, "get_portal_page"): portal_page = sent_via.get_portal_page() if portal_page: is_valid_recipient = cstr( sent_via.doc.email or sent_via.doc.email_id or sent_via.doc.contact_email) in comm.recipients if is_valid_recipient: url = "%s/%s?name=%s" % (get_url(), portal_page, urllib.quote(sent_via.doc.name)) footer = """<!-- Portal Link --><hr> <a href="%s" target="_blank">View this on our website</a>""" % url return footer
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 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,))