def validate_outgoing(self): """ Checks incoming email settings """ if self.doc.outgoing_mail_server: from webnotes.utils import cint import _socket from webnotes.utils.email_lib.send import EMail import smtplib out_email = EMail() out_email.server = self.doc.outgoing_mail_server.encode('utf-8') out_email.port = cint(self.doc.mail_port) out_email.use_ssl = self.doc.use_ssl try: out_email.login = self.doc.mail_login.encode('utf-8') out_email.password = self.doc.mail_password.encode('utf-8') except AttributeError, e: webnotes.msgprint('Login Id or Mail Password missing. Please enter and try again.') webnotes.msgprint(e) try: sess = out_email.smtp_connect() try: sess.quit() except: pass except _socket.error, e: # Invalid mail server -- due to refusing connection webnotes.msgprint('Invalid Outgoing Mail Server. Please rectify and try again.') webnotes.msgprint(e)
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)