def sendmail(recipients, sender='', msg='', subject='[No Subject]', parts=[], cc=[], attach=[], send_now=1, reply_to=None, template=None): """ send an html email as multipart with attachments and all """ from webnotes.utils.email_lib.html2text import html2text from webnotes.utils.email_lib.send import EMail email = EMail(sender, recipients, subject, reply_to=reply_to) email.cc = cc if msg: if template: msg = make_html_body(msg, template).encode('utf-8') else: # if not html, then lets put some whitespace if (not '<br>' in msg) or (not '<p>' in msg): msg = msg.replace('\n','<br>') footer = get_footer() msg = msg + (footer or '') email.set_text(html2text(msg)) email.set_html(msg) for p in parts: email.set_message(p[1]) for a in attach: email.attach(a) email.send(send_now)
def sendmail( recipients, sender="", msg="", subject="[No Subject]", parts=[], cc=[], attach=[], send_now=1, reply_to=None, template=None, from_defs=0, ): """ send an html email as multipart with attachments and all """ from webnotes.utils.email_lib.html2text import html2text from webnotes.utils.email_lib.send import EMail email = EMail(sender, recipients, subject, reply_to=reply_to, from_defs=from_defs) email.cc = cc if msg: if template: msg = make_html_body(msg, template).encode("utf-8") else: # if not html, then lets put some whitespace if (not "<br>" in msg) or (not "<p>" in msg): msg = msg.replace("\n", "<br>") footer = get_footer() msg = msg + (footer or "") email.set_text(html2text(msg)) email.set_html(msg) for p in parts: email.set_message(p[1]) for a in attach: email.attach(a) try: email.send(send_now) except smtplib.SMTPAuthenticationError: msgprint("Authentication at the mail server has failed. Please check your SMTP credentials and try again.") except: msgprint( "Mail was not sent. It could be a connection problem or you have entered the wrong data. If your data is \ correct please try after a couple of minutes." )
def sendmail(recipients, sender='', msg='', subject='[No Subject]', txt=None, \ parts=[], cc=[], attach=[], send_now=1, reply_to=None, template=None, from_defs=0): """ send an html email as multipart with attachments and all """ from webnotes.utils.email_lib.html2text import html2text from webnotes.utils.email_lib.send import EMail import HTMLParser email = EMail(sender, recipients, subject, reply_to=reply_to, from_defs=from_defs) email.cc = cc if msg: if template: msg = make_html_body(msg, template) else: # if not html, then lets put some whitespace if (not '<br>' in msg) and (not '<p>' in msg): msg = msg.replace('\n','<br>') footer = get_footer() # encode using utf-8 footer = footer.encode('utf-8', 'ignore') msg = msg + (footer or '') if txt: email.set_text(txt) else: try: msg_unicode = msg if isinstance(msg, str): msg_unicode = unicode(msg, 'utf-8', 'ignore') email.set_text(html2text(msg_unicode)) except HTMLParser.HTMLParseError: pass email.set_html(msg) for p in parts: email.set_message(p[1]) for a in attach: email.attach(a) email.send(send_now)
def sendmail(recipients, sender='', msg='', subject='[No Subject]', parts=[], cc=[], attach=[], send_now=1, reply_to=None, template=None, from_defs=0): """ send an html email as multipart with attachments and all """ from webnotes.utils.email_lib.html2text import html2text from webnotes.utils.email_lib.send import EMail email = EMail(sender, recipients, subject, reply_to=reply_to, from_defs=from_defs) email.cc = cc if msg: if template: msg = make_html_body(msg, template).encode('utf-8') else: # if not html, then lets put some whitespace if (not '<br>' in msg) or (not '<p>' in msg): msg = msg.replace('\n', '<br>') footer = get_footer() msg = msg + (footer or '') email.set_text(html2text(msg)) email.set_html(msg) for p in parts: email.set_message(p[1]) for a in attach: email.attach(a) email.send(send_now)