Example #1
0
	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)
Example #2
0
	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 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:
				err_msg = "Login Id or Mail Password missing. Please enter and try again."
				if not (self.doc.mail_login and self.doc.mail_password):
					raise AttributeError, err_msg
				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(err_msg)
				raise e
			
			# exceptions are handled in smtp_connect
			sess = out_email.smtp_connect()
			
			try:
				sess.quit()
			except:
				pass
Example #4
0
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()
		msg = msg + (footer or '')
		if txt:
			email.set_text(txt)
		else:
			try:
				email.set_text(html2text(msg))
			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)
Example #5
0
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)
Example #6
0
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)
Example #7
0
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."
        )