예제 #1
0
파일: bulk.py 프로젝트: maticaZA/basic
def flush(from_test=False):
	"""flush email queue, every time: called from scheduler"""
	smtpserver = SMTPServer()

	auto_commit = not from_test

	if frappe.flags.mute_emails or frappe.conf.get("mute_emails") or False:
		msgprint(_("Emails are muted"))
		from_test = True

	for i in xrange(500):
		email = frappe.db.sql("""select * from `tabBulk Email` where
			status='Not Sent' limit 1 for update""", as_dict=1)
		if email:
			email = email[0]
		else:
			break

		frappe.db.sql("""update `tabBulk Email` set status='Sending' where name=%s""",
			(email["name"],), auto_commit=auto_commit)
		try:
			if not from_test:
				smtpserver.sess.sendmail(email["sender"], email["recipient"], email["message"])

			frappe.db.sql("""update `tabBulk Email` set status='Sent' where name=%s""",
				(email["name"],), auto_commit=auto_commit)

		except Exception, e:
			frappe.db.sql("""update `tabBulk Email` set status='Error', error=%s
				where name=%s""", (unicode(e), email["name"]), auto_commit=auto_commit)
예제 #2
0
	def validate(self):
		if self.mail_server:
			from frappe.utils import cint
			from frappe.utils.email_lib.smtp import SMTPServer
			smtpserver = SMTPServer(login = self.mail_login,
				password = self.mail_password,
				server = self.mail_server,
				port = cint(self.mail_port),
				use_ssl = self.use_ssl
			)
						
			# exceptions are handled in session connect
			sess = smtpserver.sess
예제 #3
0
    def validate_outgoing(self):
        """Checks incoming email settings"""
        self.doc.encode()
        if self.doc.outgoing_mail_server:
            from frappe.utils import cint
            from frappe.utils.email_lib.smtp import SMTPServer
            smtpserver = SMTPServer(login=self.doc.mail_login,
                                    password=self.doc.mail_password,
                                    server=self.doc.outgoing_mail_server,
                                    port=cint(self.doc.mail_port),
                                    use_ssl=self.doc.use_ssl)

            # exceptions are handled in session connect
            sess = smtpserver.sess
예제 #4
0
파일: bulk.py 프로젝트: maticaZA/basic
	def check_bulk_limit(new_mails):
		this_month = frappe.db.sql("""select count(*) from `tabBulk Email` where
			month(creation)=month(%s)""" % nowdate())[0][0]

		# No limit for own email settings
		smtp_server = SMTPServer()
		if smtp_server.email_settings and cint(smtp_server.email_settings.enabled):
			monthly_bulk_mail_limit = 999999
		else:
			monthly_bulk_mail_limit = frappe.conf.get('monthly_bulk_mail_limit') or 500

		if ( this_month + len(recipients) ) > monthly_bulk_mail_limit:
			throw(_("Bulk email limit {0} crossed").format(monthly_bulk_mail_limit),
				BulkLimitCrossedError)
예제 #5
0
	def validate(self):
		if self.auto_email_id and not validate_email_add(self.auto_email_id):
			throw(_("{0} is not a valid email id").format(self.auto_email_id), frappe.InvalidEmailAddressError)

		if self.mail_server and not frappe.local.flags.in_patch:
			from frappe.utils import cint
			from frappe.utils.email_lib.smtp import SMTPServer
			smtpserver = SMTPServer(login = self.mail_login,
				password = self.mail_password,
				server = self.mail_server,
				port = cint(self.mail_port),
				use_ssl = cint(self.use_ssl)
			)

			# exceptions are handled in session connect
			sess = smtpserver.sess