Beispiel #1
0
    def validate(self):
        self._prev = frappe._dict(
            {
                "contact_date": frappe.db.get_value("Lead", self.name, "contact_date")
                if (not cint(self.get("__islocal")))
                else None,
                "contact_by": frappe.db.get_value("Lead", self.name, "contact_by")
                if (not cint(self.get("__islocal")))
                else None,
            }
        )

        self.set_status()
        self.check_email_id_is_unique()

        if self.source == "Campaign" and not self.campaign_name and session["user"] != "Guest":
            frappe.throw(_("Campaign Name is required"))

        if self.email_id:
            if not self.flags.ignore_email_validation:
                validate_email_add(self.email_id, True)

            if self.email_id == self.lead_owner:
                # Lead Owner cannot be same as the Lead
                self.lead_owner = None

            self.image = has_gravatar(self.email_id)
Beispiel #2
0
	def validate(self):
		"""Validate email id and check POP3 and SMTP connections is enabled."""
		if self.email_id:
			validate_email_add(self.email_id, True)

		if self.login_id_is_different:
			if not self.login_id:
				frappe.throw(_("Login Id is required"))
		else:
			self.login_id = None

		if frappe.local.flags.in_patch or frappe.local.flags.in_test:
			return

		if self.enable_incoming and not self.append_to:
			frappe.throw(_("Append To is mandatory for incoming mails"))

		if not frappe.local.flags.in_install and not frappe.local.flags.in_patch:
			if self.enable_incoming:
				self.get_pop3()

			if self.enable_outgoing:
				self.check_smtp()

		if self.notify_if_unreplied:
			if not self.send_notification_to:
				frappe.throw(_("{0} is mandatory").format(self.meta.get_label("send_notification_to")))
			for e in self.get_unreplied_notification_emails():
				validate_email_add(e, True)

		if self.enable_incoming and self.append_to:
			valid_doctypes = [d[0] for d in get_append_to()]
			if self.append_to not in valid_doctypes:
				frappe.throw(_("Append To can be one of {0}").format(comma_or(valid_doctypes)))
Beispiel #3
0
    def validate(self):
        """Validate email id and check POP3 and SMTP connections is enabled."""
        if self.email_id:
            validate_email_add(self.email_id, True)

        if self.login_id_is_different:
            if not self.login_id:
                frappe.throw(_("Login Id is required"))
        else:
            self.login_id = None

        if frappe.local.flags.in_patch or frappe.local.flags.in_test:
            return

        if self.enable_incoming and not self.append_to:
            frappe.throw(_("Append To is mandatory for incoming mails"))

        if not frappe.local.flags.in_install and not frappe.local.flags.in_patch:
            if self.enable_incoming:
                self.get_pop3()

            if self.enable_outgoing:
                self.check_smtp()

        if self.notify_if_unreplied:
            for e in self.get_unreplied_notification_emails():
                validate_email_add(e, True)
Beispiel #4
0
	def validate(self):
		self.set_lead_name()
		self._prev = frappe._dict({
			"contact_date": frappe.db.get_value("Lead", self.name, "contact_date") if \
				(not cint(self.get("__islocal"))) else None,
			"contact_by": frappe.db.get_value("Lead", self.name, "contact_by") if \
				(not cint(self.get("__islocal"))) else None,
		})

		self.set_status()
		self.check_email_id_is_unique()

		if self.email_id:
			if not self.flags.ignore_email_validation:
				validate_email_add(self.email_id, True)

			if self.email_id == self.lead_owner:
				frappe.throw(_("Lead Owner cannot be same as the Lead"))

			if self.email_id == self.contact_by:
				frappe.throw(_("Next Contact By cannot be same as the Lead Email Address"))

			if self.is_new() or not self.image:
				self.image = has_gravatar(self.email_id)

		if self.contact_date and getdate(self.contact_date) < getdate(nowdate()):
			frappe.throw(_("Next Contact Date cannot be in the past"))
Beispiel #5
0
	def validate(self):
		self._prev = frappe._dict({
			"contact_date": frappe.db.get_value("Lead", self.name, "contact_date") if \
				(not cint(self.get("__islocal"))) else None,
			"contact_by": frappe.db.get_value("Lead", self.name, "contact_by") if \
				(not cint(self.get("__islocal"))) else None,
		})

		self.set_status()
		self.check_email_id_is_unique()

		if self.email_id:
			if not self.flags.ignore_email_validation:
				validate_email_add(self.email_id, True)

			if self.email_id == self.lead_owner:
				frappe.throw(_("Lead Owner cannot be same as the Lead"))

			if self.email_id == self.contact_by:
				frappe.throw(_("Next Contact By cannot be same as the Lead Email Address"))

			if self.is_new() or not self.image:
				self.image = has_gravatar(self.email_id)

		if self.contact_date and getdate(self.contact_date) < getdate(nowdate()):
			frappe.throw(_("Next Contact Date cannot be in the past"))
	def validate(self):
		self.check_email_id_is_unique()
		validate_email_add(self.email_id, True)

		if not self.applicant_name and self.email_id:
			guess = self.email_id.split('@')[0]
			self.applicant_name = ' '.join([p.capitalize() for p in guess.split('.')])
Beispiel #7
0
	def validate(self):
		"""Validate email id and check POP3 and SMTP connections is enabled."""
		if self.email_id:
			validate_email_add(self.email_id, True)

		if self.login_id_is_different:
			if not self.login_id:
				frappe.throw(_("Login Id is required"))
		else:
			self.login_id = None

		if frappe.local.flags.in_patch or frappe.local.flags.in_test:
			return

		if self.enable_incoming and not self.append_to:
			frappe.throw(_("Append To is mandatory for incoming mails"))

		if not frappe.local.flags.in_install and not frappe.local.flags.in_patch:
			if self.enable_incoming:
				self.get_pop3()

			if self.enable_outgoing:
				self.check_smtp()

		if self.notify_if_unreplied:
			for e in self.get_unreplied_notification_emails():
				validate_email_add(e, True)
	def validate(self):
		"""Validate email id and check POP3/IMAP and SMTP connections is enabled."""
		if self.email_id:
			validate_email_add(self.email_id, True)

		if self.login_id_is_different:
			if not self.login_id:
				frappe.throw(_("Login Id is required"))
		else:
			self.login_id = None

		if frappe.local.flags.in_patch or frappe.local.flags.in_test:
			return

		if self.enable_incoming and not self.append_to:
			frappe.throw(_("Append To is mandatory for incoming mails"))

		if not frappe.local.flags.in_install and not frappe.local.flags.in_patch:
			if self.enable_incoming:
				self.get_pop3()

			if self.enable_outgoing:
				self.check_smtp()

		if self.notify_if_unreplied:
			if not self.send_notification_to:
				frappe.throw(_("{0} is mandatory").format(self.meta.get_label("send_notification_to")))
			for e in self.get_unreplied_notification_emails():
				validate_email_add(e, True)

		if self.enable_incoming and self.append_to:
			valid_doctypes = [d[0] for d in get_append_to()]
			if self.append_to not in valid_doctypes:
				frappe.throw(_("Append To can be one of {0}").format(comma_or(valid_doctypes)))
def add_subscribers(name, email_list):
    if not isinstance(email_list, (list, tuple)):
        email_list = email_list.replace(",", "\n").split("\n")
    count = 0
    for email in email_list:
        email = email.strip()
        validate_email_add(email, True)

        if email:
            if not frappe.db.get_value("Newsletter List Subscriber", {
                    "newsletter_list": name,
                    "email": email
            }):
                frappe.get_doc({
                    "doctype": "Newsletter List Subscriber",
                    "newsletter_list": name,
                    "email": email
                }).insert(ignore_permissions=frappe.flags.ignore_permissions)

                count += 1
            else:
                pass

    frappe.msgprint(_("{0} subscribers added").format(count))

    return frappe.get_doc("Newsletter List", name).update_total_subscribers()
Beispiel #10
0
    def set_sender_full_name(self):
        if not self.sender_full_name and self.sender:
            if self.sender == "Administrator":
                self.sender_full_name = frappe.db.get_value(
                    "User", "Administrator", "full_name")
                self.sender = frappe.db.get_value("User", "Administrator",
                                                  "email")
            elif self.sender == "Guest":
                self.sender_full_name = self.sender
                self.sender = None
            else:
                if self.sent_or_received == 'Sent':
                    validate_email_add(self.sender, throw=True)

                sender_name, sender_email = parseaddr(self.sender)

                if not sender_name:
                    sender_name = get_fullname(sender_email)
                    if sender_name == sender_email:
                        sender_name = None

                self.sender = sender_email
                self.sender_full_name = sender_name or get_fullname(
                    frappe.session.user
                ) if frappe.session.user != 'Administrator' else None
Beispiel #11
0
	def validate(self):
		self.check_email_id_is_unique()
		validate_email_add(self.email_id, True)

		if not self.applicant_name and self.email_id:
			guess = self.email_id.split('@')[0]
			self.applicant_name = ' '.join([p.capitalize() for p in guess.split('.')])
Beispiel #12
0
    def set_sender_full_name(self):
        if not self.sender_full_name and self.sender:
            if self.sender == "Administrator":
                self.sender_full_name = frappe.db.get_value(
                    "User", "Administrator", "full_name")
                self.sender = frappe.db.get_value("User", "Administrator",
                                                  "email")
            elif self.sender == "Guest":
                self.sender_full_name = self.sender
                self.sender = None
            else:
                if self.sent_or_received == 'Sent':
                    validate_email_add(self.sender, throw=True)

                sender_name, sender_email = parse_addr(self.sender)
                if sender_name == sender_email:
                    sender_name = None

                self.sender = sender_email
                self.sender_full_name = sender_name

                if not self.sender_full_name:
                    self.sender_full_name = frappe.db.get_value(
                        'User', self.sender, 'full_name')

                if not self.sender_full_name:
                    first_name, last_name = frappe.db.get_value(
                        'Contact',
                        filters={'email_id': sender_email},
                        fieldname=['first_name', 'last_name']) or [None, None]
                    self.sender_full_name = (first_name or '') + (last_name
                                                                  or '')

                if not self.sender_full_name:
                    self.sender_full_name = sender_email
Beispiel #13
0
	def set_sender_full_name(self):
		if not self.sender_full_name and self.sender:
			if self.sender == "Administrator":
				self.sender_full_name = self.sender
				self.sender = frappe.db.get_value("User", "Administrator", "email")
			else:
				validate_email_add(self.sender, throw=True)
				self.sender_full_name = get_fullname(self.sender)
Beispiel #14
0
	def validate(self):
		validate_email_add(self.email_address.strip(), True)
		if self.residential_tel:
			validate_mobile(self.residential_tel)
		if self.office_tel:
			validate_mobile(self.office_tel)
		if self.mobile:
			validate_mobile(self.mobile)
 def set_sender_full_name(self):
     if not self.sender_full_name and self.sender:
         if self.sender == "Administrator":
             self.sender_full_name = self.sender
             self.sender = frappe.db.get_value("User", "Administrator",
                                               "email")
         else:
             validate_email_add(self.sender, throw=True)
             self.sender_full_name = get_fullname(self.sender)
Beispiel #16
0
    def validate(self):
        """Validate Email Address and check POP3/IMAP and SMTP connections is enabled."""
        if self.email_id:
            validate_email_add(self.email_id, True)

        if self.login_id_is_different:
            if not self.login_id:
                frappe.throw(_("Login Id is required"))
        else:
            self.login_id = None

        duplicate_email_account = frappe.get_all("Email Account",
                                                 filters={
                                                     "email_id": self.email_id,
                                                     "name": ("!=", self.name)
                                                 })
        if duplicate_email_account:
            frappe.throw(
                _("Email ID must be unique, Email Account already exists \
				for {0}".format(frappe.bold(self.email_id))))

        if frappe.local.flags.in_patch or frappe.local.flags.in_test:
            return

        #if self.enable_incoming and not self.append_to:
        #	frappe.throw(_("Append To is mandatory for incoming mails"))

        if (not self.awaiting_password and not frappe.local.flags.in_install
                and not frappe.local.flags.in_patch):
            if self.password or self.smtp_server in ('127.0.0.1', 'localhost'):
                if self.enable_incoming:
                    self.get_incoming_server()
                    self.no_failed = 0

                if self.enable_outgoing:
                    self.check_smtp()
            else:
                if self.enable_incoming or (self.enable_outgoing and
                                            not self.no_smtp_authentication):
                    frappe.throw(
                        _("Password is required or select Awaiting Password"))

        if self.notify_if_unreplied:
            if not self.send_notification_to:
                frappe.throw(
                    _("{0} is mandatory").format(
                        self.meta.get_label("send_notification_to")))
            for e in self.get_unreplied_notification_emails():
                validate_email_add(e, True)

        if self.enable_incoming and self.append_to:
            valid_doctypes = [d[0] for d in get_append_to()]
            if self.append_to not in valid_doctypes:
                frappe.throw(
                    _("Append To can be one of {0}").format(
                        comma_or(valid_doctypes)))
Beispiel #17
0
def validate_email(doc):
	"""Validate Email Addresses of Recipients and CC"""
	if not (doc.communication_type=="Communication" and doc.communication_medium == "Email"):
		return

	# validate recipients
	for email in split_emails(doc.recipients):
		validate_email_add(email, throw=True)

	# validate CC
	for email in split_emails(doc.cc):
		validate_email_add(email, throw=True)
Beispiel #18
0
	def validate_emails(self):
		'''Cleanup list of emails'''
		if ',' in self.email_to:
			self.email_to.replace(',', '\n')

		valid = []
		for email in self.email_to.split():
			if email:
				validate_email_add(email, True)
				valid.append(email)

		self.email_to = '\n'.join(valid)
    def validate_emails(self):
        '''Cleanup list of emails'''
        if ',' in self.email_to:
            self.email_to.replace(',', '\n')

        valid = []
        for email in self.email_to.split():
            if email:
                validate_email_add(email, True)
                valid.append(email)

        self.email_to = '\n'.join(valid)
Beispiel #20
0
def check_for_duplicate_email_id(user):
  email_ids = user.split(',')
  email_ids = [email for email in email_ids if email]
  if email_ids:
    email_count = Counter(email_ids)
    for email_id, count in email_count.items():
      validate_email_add(email_id, True)
      if count > 1:
        frappe.throw("Email Id {0} has been added {1} times".format(email_id, count))
    return email_ids
  else:
    frappe.throw("Email Id is mandatory field")      
Beispiel #21
0
    def validate(self):
        self.check_email_id_is_unique()
        self.check_identity_is_unique()
        if not self.company:
            self.company = frappe.defaults.get_global_default("company")
        if self.email_id:
            validate_email_add(self.email_id, True)

        if not self.applicant_name and self.email_id:
            guess = self.email_id.split('@')[0]
            self.applicant_name = ' '.join(
                [p.capitalize() for p in guess.split('.')])
Beispiel #22
0
def validate_email(doc):
	"""Validate Email Addresses of Recipients and CC"""
	if not (doc.communication_type=="Communication" and doc.communication_medium == "Email") or doc.flags.in_receive:
		return

	# validate recipients
	for email in split_emails(doc.recipients):
		validate_email_add(email, throw=True)

	# validate CC
	for email in split_emails(doc.cc):
		validate_email_add(email, throw=True)
Beispiel #23
0
def check_for_duplicate_email_id(user):
    email_ids = user.split(',')
    email_ids = [email for email in email_ids if email]
    if email_ids:
        email_count = Counter(email_ids)
        for email_id, count in email_count.items():
            validate_email_add(email_id, True)
            if count > 1:
                frappe.throw("Email Id {0} has been added {1} times".format(
                    email_id, count))
        return email_ids
    else:
        frappe.throw("Email Id is mandatory field")
    def validate(self):
        self.check_email_id_is_unique()
        if self.email_id:
            validate_email_add(self.email_id, True)

        if not self.applicant_name and self.email_id:
            guess = self.email_id.split('@')[0]
            self.applicant_name = ' '.join(
                [p.capitalize() for p in guess.split('.')])
        try:
            datetime.datetime.strptime(self.birth_date, '%Y-%m-%d')
        except ValueError:
            frappe.throw("Date must be in format: dd-mm-yyyy")
	def validate(self):
		if self.get("__islocal"):
			if self.reference_doctype and self.reference_name:
				self.status = "Linked"
			else:
				self.status = "Open"

		# validate recipients
		for email in split_emails(self.recipients):
			validate_email_add(email, throw=True)

		# validate CC
		for email in split_emails(self.cc):
			validate_email_add(email, throw=True)
Beispiel #26
0
    def validate(self):
        if self.get("__islocal"):
            if self.reference_doctype and self.reference_name:
                self.status = "Linked"
            else:
                self.status = "Open"

        # validate recipients
        for email in split_emails(self.recipients):
            validate_email_add(email, throw=True)

        # validate CC
        for email in split_emails(self.cc):
            validate_email_add(email, throw=True)
Beispiel #27
0
	def validate(self):
		"""Validate Email Address and check POP3/IMAP and SMTP connections is enabled."""
		if self.email_id:
			validate_email_add(self.email_id, True)

		if self.login_id_is_different:
			if not self.login_id:
				frappe.throw(_("Login Id is required"))
		else:
			self.login_id = None

		duplicate_email_account = frappe.get_all("Email Account", filters={
			"email_id": self.email_id,
			"name": ("!=", self.name)
		})
		if duplicate_email_account:
			frappe.throw(_("Email id must be unique, Email Account is already exist \
				for {0}".format(frappe.bold(self.email_id))))

		if frappe.local.flags.in_patch or frappe.local.flags.in_test:
			return

		#if self.enable_incoming and not self.append_to:
		#	frappe.throw(_("Append To is mandatory for incoming mails"))

		if (not self.awaiting_password and not frappe.local.flags.in_install
			and not frappe.local.flags.in_patch):
			if self.password or self.smtp_server in ('127.0.0.1', 'localhost'):
				if self.enable_incoming:
					self.get_incoming_server()
					self.no_failed = 0


				if self.enable_outgoing:
					self.check_smtp()
			else:
				if self.enable_incoming or self.enable_outgoing:
					frappe.throw(_("Password is required or select Awaiting Password"))

		if self.notify_if_unreplied:
			if not self.send_notification_to:
				frappe.throw(_("{0} is mandatory").format(self.meta.get_label("send_notification_to")))
			for e in self.get_unreplied_notification_emails():
				validate_email_add(e, True)

		if self.enable_incoming and self.append_to:
			valid_doctypes = [d[0] for d in get_append_to()]
			if self.append_to not in valid_doctypes:
				frappe.throw(_("Append To can be one of {0}").format(comma_or(valid_doctypes)))
Beispiel #28
0
	def validate(self):
		"""validate the email ids"""
		from frappe.utils import validate_email_add

		if not self.sender:
			self.sender = self.get_default_sender()

		validate_email_add(strip(self.sender), True)
		self.reply_to = validate_email_add(strip(self.reply_to) or self.sender, True)

		self.recipients = [strip(r) for r in self.recipients]
		self.cc = [strip(r) for r in self.cc]

		for e in self.recipients + (self.cc or []):
			validate_email_add(e, True)
Beispiel #29
0
	def validate(self):
		"""
			Validations:
				1.validate proper email
				2.Same email id should not be entered by same user
				3.Currently check that only users having trufil domain allowed(Remaining)
				4.Check SMTP and POP
		"""
		if self.email_id:
			validate_email_add(self.email_id, True)
			self.validate_duplicate_emailid_config()

		if self.enabled:
			self.get_pop3()
			self.check_smtp()
Beispiel #30
0
    def validate(self):
        """validate the email ids"""
        from frappe.utils import validate_email_add

        if not self.sender:
            self.sender = self.get_default_sender()

        validate_email_add(strip(self.sender), True)
        self.reply_to = validate_email_add(strip(self.reply_to) or self.sender, True)

        self.recipients = [strip(r) for r in self.recipients]
        self.cc = [strip(r) for r in self.cc]

        for e in self.recipients + (self.cc or []):
            validate_email_add(e, True)
Beispiel #31
0
    def make_new_lead_if_required(self):
        """Set lead against new opportunity"""
        if not (self.lead or
                self.customer) and self.contact_email and validate_email_add(
                    self.contact_email):
            lead_name = frappe.db.get_value("Lead",
                                            {"email_id": self.contact_email})
            if not lead_name:
                sender_name = get_fullname(self.contact_email)
                if sender_name == self.contact_email:
                    sender_name = None

                if not sender_name and ('@' in self.contact_email):
                    email_name = self.contact_email.split('@')[0]

                    email_split = email_name.split('.')
                    sender_name = ''
                    for s in email_split:
                        sender_name += s.capitalize() + ' '

                lead = frappe.get_doc({
                    "doctype": "Lead",
                    "email_id": self.contact_email,
                    "lead_name": sender_name
                })

                lead.insert(ignore_permissions=True)
                lead_name = lead.name

            self.enquiry_from = "Lead"
            self.lead = lead_name
Beispiel #32
0
	def make_new_lead_if_required(self):
		"""Set lead against new opportunity"""
		if not (self.lead or self.customer) and self.contact_email and validate_email_add(self.contact_email):
			lead_name = frappe.db.get_value("Lead", {"email_id": self.contact_email})
			if not lead_name:
				sender_name = get_fullname(self.contact_email)
				if sender_name == self.contact_email:
					sender_name = None

				if not sender_name and ('@' in self.contact_email):
					email_name = self.contact_email.split('@')[0]

					email_split = email_name.split('.')
					sender_name = ''
					for s in email_split:
						sender_name += s.capitalize() + ' '

				lead = frappe.get_doc({
					"doctype": "Lead",
					"email_id": self.contact_email,
					"lead_name": sender_name
				})

				lead.insert(ignore_permissions=True)
				lead_name = lead.name

			self.enquiry_from = "Lead"
			self.lead = lead_name
Beispiel #33
0
	def validate(self):
		self._prev = frappe._dict({
			"contact_date": frappe.db.get_value("Lead", self.name, "contact_date") if \
				(not cint(self.get("__islocal"))) else None,
			"contact_by": frappe.db.get_value("Lead", self.name, "contact_by") if \
				(not cint(self.get("__islocal"))) else None,
		})

		self.set_status()

		if self.source == 'Campaign' and not self.campaign_name and session['user'] != 'Guest':
			frappe.throw(_("Campaign Name is required"))

		if self.email_id:
			if not validate_email_add(self.email_id):
				frappe.throw(_('{0} is not a valid email id').format(self.email_id))

			if self.email_id == self.lead_owner:
				# Lead Owner cannot be same as the Lead
				self.lead_owner = None
		from frappe.utils import get_url, cstr
		if self.get("__islocal") and get_url()=='http://tailorpad.com':
			frappe.errprint("creating site from lead")
			frappe.get_doc({
					"doctype": "Site Master",
					"client_name": self.company_name,
					"site_name":  self.company_name,
					"email_id__if_administrator": self.email_id,
					"country": self.country					
				}).insert()
Beispiel #34
0
    def validate(self):
        self._prev = frappe._dict({
         "contact_date": frappe.db.get_value("Lead", self.name, "contact_date") if \
          (not cint(self.get("__islocal"))) else None,
         "contact_by": frappe.db.get_value("Lead", self.name, "contact_by") if \
          (not cint(self.get("__islocal"))) else None,
        })

        self.set_status()

        if self.source == 'Campaign' and not self.campaign_name and session[
                'user'] != 'Guest':
            frappe.throw(_("Campaign Name is required"))

        if self.email_id:
            if not validate_email_add(self.email_id):
                frappe.throw(
                    _('{0} is not a valid email id').format(self.email_id))

            if self.email_id == self.lead_owner:
                # Lead Owner cannot be same as the Lead
                self.lead_owner = None
        from frappe.utils import get_url, cstr
        if self.get("__islocal") and get_url() == 'http://tailorpad.com':
            frappe.errprint("creating site from lead")
            frappe.get_doc({
                "doctype": "Site Master",
                "client_name": self.company_name,
                "site_name": self.company_name,
                "email_id__if_administrator": self.email_id,
                "country": self.country
            }).insert()
Beispiel #35
0
	def set_sender_full_name(self):
		if not self.sender_full_name and self.sender:
			if self.sender == "Administrator":
				self.sender_full_name = frappe.db.get_value("User", "Administrator", "full_name")
				self.sender = frappe.db.get_value("User", "Administrator", "email")
			elif self.sender == "Guest":
				self.sender_full_name = self.sender
				self.sender = None
			else:
				if self.sent_or_received=='Sent':
					validate_email_add(self.sender, throw=True)
				sender_name, sender_email = parse_addr(self.sender)
				if sender_name == sender_email:
					sender_name = None
				self.sender = sender_email
				self.sender_full_name = sender_name or frappe.db.exists("Contact", {"email_id": sender_email}) or sender_email
Beispiel #36
0
def evaluate_alert(doc, alert, event):
	if isinstance(alert, basestring):
		alert = frappe.get_doc("Email Alert", alert)
	if alert.condition:
		if not eval(alert.condition, {"doc": doc}):
			return

	if event=="Value Change" and not doc.is_new():
		if doc.get(alert.value_changed) == frappe.db.get_value(doc.doctype,
			doc.name, alert.value_changed):
			return # value not changed

	for recipient in alert.email_alert_recipients:
		recipients = []
		if recipient.condition:
			if not eval(recipient.condition, {"doc": doc}):
				continue
		if recipient.email_by_document_field:
			if validate_email_add(doc.get(recipient.email_by_document_field)):
				recipients.append(doc.get(recipient.email_by_document_field))
			# else:
			# 	print "invalid email"
		if recipient.cc:
			recipient.cc = recipient.cc.replace(",", "\n")
			recipients = recipients + recipient.cc.split("\n")

	if not recipients:
		return

	template = alert.message + footer
	# send alert
	frappe.sendmail(recipients=recipients, subject=alert.subject,
		message= frappe.render_template(template, {"doc": doc, "alert":alert}),
		bulk=True, ref_doctype = doc.doctype, ref_docname = doc.name)
Beispiel #37
0
def add_subscribers(name, email_list):
	if not isinstance(email_list, (list, tuple)):
		email_list = email_list.replace(",", "\n").split("\n")
	count = 0
	for email in email_list:
		email = email.strip()
		parsed_email = validate_email_add(email, False)

		if parsed_email:
			if not frappe.db.get_value("Email Group Member",
				{"email_group": name, "email": parsed_email}):
				frappe.get_doc({
					"doctype": "Email Group Member",
					"email_group": name,
					"email": parsed_email
				}).insert(ignore_permissions = frappe.flags.ignore_permissions)

				count += 1
			else:
				pass
		else:
			frappe.msgprint(_("{0} is not a valid Email Address").format(email))

	frappe.msgprint(_("{0} subscribers added").format(count))

	return frappe.get_doc("Email Group", name).update_total_subscribers()
	def validate(self):
		"""
			Validations:
				1.validate proper email
				2.Same email id should not be entered by same user
				3.Currently check that only users having trufil domain allowed(Remaining)
				4.Check SMTP and POP
		"""
		if self.email_id:
			validate_email_add(self.email_id, True)
			self.valid_trufil_id()
			self.validate_duplicate_emailid_config()

		if self.enabled:
			self.get_imap()
			self.check_smtp()
Beispiel #39
0
	def set_sender_full_name(self):
		if not self.sender_full_name and self.sender:
			if self.sender == "Administrator":
				self.sender_full_name = frappe.db.get_value("User", "Administrator", "full_name")
				self.sender = frappe.db.get_value("User", "Administrator", "email")
			elif self.sender == "Guest":
				self.sender_full_name = self.sender
				self.sender = None
			else:
				if self.sent_or_received=='Sent':
					validate_email_add(self.sender, throw=True)
				sender_name, sender_email = parse_addr(self.sender)
				if sender_name == sender_email:
					sender_name = None
				self.sender = sender_email
				self.sender_full_name = sender_name or get_fullname(frappe.session.user) if frappe.session.user!='Administrator' else None
Beispiel #40
0
def add_subscribers(name, email_list):
	if not isinstance(email_list, (list, tuple)):
		email_list = email_list.replace(",", "\n").split("\n")
	count = 0
	for email in email_list:
		email = email.strip()
		valid = validate_email_add(email, False)

		if valid:
			if not frappe.db.get_value("Newsletter List Subscriber",
				{"newsletter_list": name, "email": email}):
				frappe.get_doc({
					"doctype": "Newsletter List Subscriber",
					"newsletter_list": name,
					"email": email
				}).insert(ignore_permissions = frappe.flags.ignore_permissions)

				count += 1
			else:
				pass
		else:
			frappe.msgprint(_("{0} is not a valid email id").format(email))

	frappe.msgprint(_("{0} subscribers added").format(count))

	return frappe.get_doc("Newsletter List", name).update_total_subscribers()
Beispiel #41
0
def add_subscribers(name, email_list):
    if not isinstance(email_list, (list, tuple)):
        email_list = email_list.replace(",", "\n").split("\n")
    count = 0
    for email in email_list:
        email = email.strip()
        parsed_email = validate_email_add(email, False)

        if parsed_email:
            if not frappe.db.get_value("Email Group Member", {
                    "email_group": name,
                    "email": parsed_email
            }):
                frappe.get_doc({
                    "doctype": "Email Group Member",
                    "email_group": name,
                    "email": parsed_email
                }).insert(ignore_permissions=frappe.flags.ignore_permissions)

                count += 1
            else:
                pass
        else:
            frappe.msgprint(
                _("{0} is not a valid Email Address").format(email))

    frappe.msgprint(_("{0} subscribers added").format(count))

    return frappe.get_doc("Email Group", name).update_total_subscribers()
Beispiel #42
0
    def get_list_of_recipients(self, doc, context):
        recipients = []
        for recipient in self.recipients:
            if recipient.condition:
                if not frappe.safe_eval(recipient.condition, None, context):
                    continue
            if recipient.email_by_document_field:
                email_ids_value = doc.get(recipient.email_by_document_field)
                if validate_email_add(email_ids_value):
                    email_ids = email_ids_value.replace(",", "\n")
                    recipients = recipients + email_ids.split("\n")

                # else:
                # 	print "invalid email"
            if recipient.cc and "{" in recipient.cc:
                recipient.cc = frappe.render_template(recipient.cc, context)

            if recipient.cc:
                recipient.cc = recipient.cc.replace(",", "\n")
                recipients = recipients + recipient.cc.split("\n")

            #For sending emails to specified role
            if recipient.email_by_role:
                emails = get_emails_from_role(recipient.email_by_role)

                for email in emails:
                    recipients = recipients + email.split("\n")

        if not recipients:
            return

        return list(set(recipients))
Beispiel #43
0
 def _validate(email):
     """validate an email field"""
     if email and not validate_email_add(email):
         throw(
             _("{0} is not a valid email id").format(email),
             frappe.InvalidEmailAddressError)
     return email
Beispiel #44
0
	def validate(self):
		"""validate the Email Addresses"""
		from frappe.utils import validate_email_add

		if not self.sender:
			self.sender = self.email_account.default_sender

		validate_email_add(strip(self.sender), True)
		self.reply_to = validate_email_add(strip(self.reply_to) or self.sender, True)

		self.replace_sender()

		self.recipients = [strip(r) for r in self.recipients]
		self.cc = [strip(r) for r in self.cc]

		for e in self.recipients + (self.cc or []):
			validate_email_add(e, True)
Beispiel #45
0
def validate_cc_and_bcc(mailbox_doc,return_dic):
	for recipients in [get_recipients(mailbox_doc['cc']),get_recipients(mailbox_doc['bcc'])]:
		for recipient in recipients:
			if recipient and not validate_email_add(recipient):
				return_dic.update({"not_valid":"'%s' not valid Email Address"%recipient})
				return False

	return True		
Beispiel #46
0
	def validate(self):
		"""validate the Email Addresses"""
		from frappe.utils import validate_email_add

		if not self.sender:
			self.sender = self.email_account.default_sender

		validate_email_add(strip(self.sender), True)
		self.reply_to = validate_email_add(strip(self.reply_to) or self.sender, True)

		self.replace_sender()

		self.recipients = [strip(r) for r in self.recipients]
		self.cc = [strip(r) for r in self.cc]

		for e in self.recipients + (self.cc or []):
			validate_email_add(e, True)
Beispiel #47
0
 def _validate(email):
     """validate an email field"""
     if email and not validate_email_add(email):
         throw(
             "{email} {msg}".format(**{
                 "email": email,
                 "msg": _("is not a valid email id")
             }))
     return email
Beispiel #48
0
    def validate(self):
        """Validate email id and check POP3 and SMTP connections is enabled."""
        if self.email_id:
            validate_email_add(self.email_id, True)

        if frappe.local.flags.in_patch or frappe.local.flags.in_test:
            return

        if not frappe.local.flags.in_install and not frappe.local.flags.in_patch:
            if self.enable_incoming:
                self.get_pop3()

            if self.enable_outgoing:
                self.check_smtp()

        if self.notify_if_unreplied:
            for e in self.get_unreplied_notification_emails():
                validate_email_add(e, True)
Beispiel #49
0
    def validate_email_type(self, email):
        from frappe.utils import validate_email_add

        email = email.strip()
        if not validate_email_add(email):
            throw("{email} {msg}".format(**{
                "email": email,
                "msg": _("is not a valid email id")
            }))
Beispiel #50
0
	def validate(self):
		self.set_status()
		
		if self.doc.source == 'Campaign' and not self.doc.campaign_name and session['user'] != 'Guest':
			frappe.throw("Please specify campaign name")
		
		if self.doc.email_id:
			if not validate_email_add(self.doc.email_id):
				frappe.throw('Please enter valid email id.')
Beispiel #51
0
	def validate(self):
		"""Validate email id and check POP3 and SMTP connections is enabled."""
		if self.email_id:
			validate_email_add(self.email_id, True)

		if frappe.local.flags.in_patch or frappe.local.flags.in_test:
			return

		if not frappe.local.flags.in_install and not frappe.local.flags.in_patch:
			if self.enable_incoming:
				self.get_pop3()

			if self.enable_outgoing:
				self.check_smtp()

		if self.notify_if_unreplied:
			for e in self.get_unreplied_notification_emails():
				validate_email_add(e, True)
    def validate(self):
        """Validate email id and check POP3/IMAP and SMTP connections is enabled."""
        if self.email_id:
            validate_email_add(self.email_id, True)

        if frappe.local.flags.in_patch or frappe.local.flags.in_test:
            return

        if not frappe.local.flags.in_install and not frappe.local.flags.in_patch:
            try:
                if self.use_imap:
                    if self.use_ssl:
                        test = imaplib.IMAP4_SSL(self.email_server)
                    else:
                        test = imaplib.IMAP4(self.email_server)

                else:
                    if self.use_ssl:
                        test = poplib.POP3_SSL(self.email_server)
                    else:
                        test = poplib.POP3(self.email_server)

            except Exception:
                frappe.throw("Incoming email account not correct")
                return None
            finally:
                try:
                    if self.use_imap:
                        test.logout()
                    else:
                        test.quit()
                except Exception:
                    pass
            try:
                if self.use_tls and not self.smtp_port:
                    self.port = 587
                sess = smtplib.SMTP((self.smtp_server or "").encode('utf-8'),
                                    cint(self.smtp_port) or None)
                sess.quit()
            except Exception as e:
                frappe.throw("Outgoing email account not correct")
                return None
        return
Beispiel #53
0
	def validate(self):
		"""Validate email id and check POP3/IMAP and SMTP connections is enabled."""
		if self.email_id:
			validate_email_add(self.email_id, True)

		if frappe.local.flags.in_patch or frappe.local.flags.in_test:
			return

		if not frappe.local.flags.in_install and not frappe.local.flags.in_patch:
			try:
				if self.use_imap:
					if self.use_ssl:
						test = imaplib.IMAP4_SSL(self.email_server)
					else:
						test = imaplib.IMAP4(self.email_server)

				else:
					if self.use_ssl:
						test = poplib.POP3_SSL(self.email_server)
					else:
						test = poplib.POP3(self.email_server)

			except Exception:
				frappe.throw(_("Incoming email account not correct"))
				return None
			finally:
				try:
					if self.use_imap:
						test.logout()
					else:
						test.quit()
				except Exception:
					pass
			try:
				if self.use_tls and not self.smtp_port:
					self.smtp_port = 587
				sess = smtplib.SMTP((self.smtp_server or "").encode('utf-8'), cint(self.smtp_port) or None)
				sess.quit()
			except Exception:
				frappe.throw(_("Outgoing email account not correct"))
				return None
		return
	def set_sender_full_name(self):
		if not self.sender_full_name and self.sender:
			if self.sender == "Administrator":
				self.sender_full_name = self.sender
				self.sender = frappe.db.get_value("User", "Administrator", "email")
			elif self.sender == "Guest":
				self.sender_full_name = self.sender
				self.sender = None
			else:
				validate_email_add(self.sender, throw=True)

				sender_name, sender_email = parseaddr(self.sender)

				if not sender_name:
					sender_name = get_fullname(sender_email)
					if sender_name == sender_email:
						sender_name = None

				self.sender = sender_email
				self.sender_full_name = sender_name or get_fullname(frappe.session.user)
Beispiel #55
0
	def validate(self):
		self._prev = frappe._dict({
			"contact_date": frappe.db.get_value("Lead", self.name, "contact_date") if \
				(not cint(self.get("__islocal"))) else None,
			"contact_by": frappe.db.get_value("Lead", self.name, "contact_by") if \
				(not cint(self.get("__islocal"))) else None,
		})

		self.set_status()
		self.check_email_id_is_unique()

		if self.source == 'Campaign' and not self.campaign_name and session['user'] != 'Guest':
			frappe.throw(_("Campaign Name is required"))

		if self.email_id:
			validate_email_add(self.email_id, True)

			if self.email_id == self.lead_owner:
				# Lead Owner cannot be same as the Lead
				self.lead_owner = None
Beispiel #56
0
	def validate_email_id(self):
		if self.notify_by_email:
			if self.recipients:
				email_list = split_emails(self.recipients.replace("\n", ""))

				from frappe.utils import validate_email_add
				for email in email_list:
					if not validate_email_add(email):
						frappe.throw(_("{0} is an invalid email address in 'Recipients'").format(email))
			else:
				frappe.throw(_("'Recipients' not specified"))
	def validate(self):
		if self.date_of_birth and self.date_of_visit and getdate(self.date_of_birth) >= getdate(self.date_of_visit):		
			frappe.throw(_("Date of First Visit '{0}' must be greater than Date of Birth '{1}'").format(self.date_of_visit, self.date_of_birth))

		# if self.baptisum_status=='Yes':
		# 	if not self.baptism_when or not self.baptism_where :
		# 		frappe.throw(_("When and Where is Mandatory if 'Baptisum Status' is 'Yes'..!"))

		if self.email_id:
			if not validate_email_add(self.email_id):
				frappe.throw(_('{0} is not a valid email id').format(self.email_id))
Beispiel #58
0
	def validate_notification_email_id(self):
		if self.notification_email_address:
			email_list = filter(None, [cstr(email).strip() for email in
				self.notification_email_address.replace("\n", "").split(",")])

			from frappe.utils import validate_email_add
			for email in email_list:
				if not validate_email_add(email):
					throw(_("{0} is an invalid email address in 'Notification Email Address'").format(email))

		else:
			throw(_("'Notification Email Addresses' not specified for recurring invoice"))
Beispiel #59
0
def validate_birth(doc,method):
		#frappe.errprint("in date of birth ")
		if doc.date_of_birth and doc.date_of_join and getdate(doc.date_of_birth) >= getdate(doc.date_of_join):		
			frappe.throw(_("Date of Joining '{0}' must be greater than Date of Birth '{1}'").format(doc.date_of_join, doc.date_of_birth))
		
		# if doc.baptisum_status=='Yes':
		# 	if not doc.baptism_when or not doc.baptism_where :
		# 		frappe.throw(_("When and Where is Mandatory if 'Baptisum Status' is 'Yes'..!"))

		if doc.email_id:
			if not validate_email_add(doc.email_id):
				frappe.throw(_('{0} is not a valid email id').format(doc.email_id))
Beispiel #60
0
	def validate(self):
		if self.email_address:
			validate_email_add(self.email_address.strip(), True)
		if self.residential_tel:
			validate_mobile(self.residential_tel)
		if self.office_tel:
			validate_mobile(self.office_tel)
		if self.mobile:
			validate_mobile(self.mobile)
		
		if self.is_directory:
			if self.s_email_address:
				validate_email_add(self.s_email_address.strip(), True)
			if self.s_residential_number:
				validate_mobile(self.s_residential_number)
			if self.s_office_number:
				validate_mobile(self.s_office_number)
			if self.s_mobile_number:
				validate_mobile(self.s_mobile_number)

			for d in self.bod:
				if d.email_address:
					validate_email_add(d.email_address.strip(), True)
	
				if d.mobile_number:
					validate_mobile(d.mobile_number)