Merge branch 'master' of github.com:webnotes/erpnext
diff --git a/erpnext/home/doctype/home_control/home_control.py b/erpnext/home/doctype/home_control/home_control.py
index fba711e..b1ddda4 100644
--- a/erpnext/home/doctype/home_control/home_control.py
+++ b/erpnext/home/doctype/home_control/home_control.py
@@ -118,22 +118,6 @@
 						out[dt][s[0]] = cint(cnt)
 		return out
 		
-	def send_feedback(self, args):
-		args = json.loads(args)
-		
-		fb_sender = sql("select concat_ws(' ',first_name, last_name), email from tabProfile where name=%s", session['user'])
-		fb_subject = 'Feedback : ' + args['subject']
-
-
-		fb_msg = '''
-			<div style="font-size:14px; padding:8px; border:1px solid #DDF">
-			<div style="margin-bottom:16px">%s wrote,</div>
-			<div>%s</div>
-			</div>
-		''' % (fb_sender[0][0], args['feedback'])
-		
-		sendmail('info@webnotestech.com', fb_sender[0][1], msg = fb_msg, subject=args['subject'],parts=[], cc=[], attach=[])
-
 	def get_dt_help(self,dt):
 		return sql("select description from tabDocType where name=%s",dt)[0][0] or ''
 
diff --git a/erpnext/projects/doctype/project_control/project_control.py b/erpnext/projects/doctype/project_control/project_control.py
index 0dcd1a9..9928ffd 100644
--- a/erpnext/projects/doctype/project_control/project_control.py
+++ b/erpnext/projects/doctype/project_control/project_control.py
@@ -155,7 +155,6 @@
 			<p>If you have already completed this task, please update the system</p>
 			<p>Good Luck!</p>
 			<p>(This notification is autogenerated)</p>""" % i
-			sendmail(i['allocated_to'], sender='automail@webnotestech.com', msg=msg2,send_now=1, \
-				subject='A task has been assigned')
+			sendmail(i['allocated_to'], msg=msg2, subject='A task has been assigned')
 			sql("update `tabTask` set sent_reminder='1' where name='%(name)s' and allocated_to= '%(allocated_to)s'" % i)	
 	
diff --git a/erpnext/projects/doctype/task/task.py b/erpnext/projects/doctype/task/task.py
index 552a4c8..bfd98db 100644
--- a/erpnext/projects/doctype/task/task.py
+++ b/erpnext/projects/doctype/task/task.py
@@ -115,10 +115,7 @@
 			<p><b>Expected End Date:</b> %(exp_end_date)s</p>
 			<p><b>Details:</b> %(description)s</p>
 			<p>(This notification is autogenerated)</p>""" % i
-		sendmail(self.doc.allocated_to, sender='automail@webnotestech.com', msg=msg2,send_now=1,\
-			subject= task_label + self.doc.subject)
-
-
+		sendmail(self.doc.allocated_to, msg=msg2,subject= task_label + self.doc.subject)
 	
 	#validate before closing task
 	def validate_for_closed(self):
diff --git a/erpnext/selling/doctype/lead/lead.js b/erpnext/selling/doctype/lead/lead.js
index 57f2bee..504b0bd 100644
--- a/erpnext/selling/doctype/lead/lead.js
+++ b/erpnext/selling/doctype/lead/lead.js
@@ -110,16 +110,6 @@
 	);
 }
 
-// send email
-// ===============================================================
-cur_frm.cscript.send_email = function(doc,cdt,cdn){
-	if(doc.__islocal != 1){
-		$c_obj(make_doclist(doc.doctype, doc.name),'send_mail','',function(r,rt){});
-	}else{
-		msgprint("Please save lead first before sending email")
-	}
-}
-
 // Create New Opportunity
 // ===============================================================
 cur_frm.cscript['Create Opportunity'] = function(){
diff --git a/erpnext/selling/doctype/lead/lead.py b/erpnext/selling/doctype/lead/lead.py
index 166e4fa..cdb278e 100644
--- a/erpnext/selling/doctype/lead/lead.py
+++ b/erpnext/selling/doctype/lead/lead.py
@@ -82,15 +82,9 @@
 		
 	
 	def on_update(self):
-		# Add to calendar
-		# ========================================================================
 		if self.doc.contact_by:
 			self.add_calendar_event()
 		
-		if session['user'] == 'Guest':
-			if self.doc.email_id:
-				self.send_email_notification()
-		
 		if not self.doc.naming_series:
 			if session['user'] == 'Guest':
 				import webnotes.model.doctype
@@ -102,37 +96,6 @@
 			else:
 				msgprint("Please specify naming series")
 				raise Exception
-	
-	def send_email_notification(self):
-		if not validate_email_add(self.doc.email_id.strip(' ')):
-			msgprint('error:%s is not a valid email id' % self.doc.email_id.strip(' '))
-			raise Exception
-		else:
-			subject = 'Thank you for interest in erpnext'
-			 
-			sendmail([self.doc.email_id.strip(' ')], sender = sender_email[0][0], subject = subject , parts = [['text/html', self.get_notification_msg()]])
-			msgprint("Mail Sent")
-	
-	def get_notification_msg(self):
-		t = """
-			<html>
-				<body>
-					Dear %s,<br><br>
-
-					Thank you for contacting us.<br><br>
-
-					You have left following message for us,<br>
-					%s
-					<br><br>
-
-					You will receive reply on this shortly.<br><br>
-
-					Cheers!
-				</body>
-			</html>
-		""" % (self.doc.lead_name, self.doc.remark)
-
-		return t
 
 	# Add to Calendar
 	# ===========================================================================
@@ -157,25 +120,6 @@
 		ev.ref_name = self.doc.name
 		ev.save(1)
 
-
-#-----------------Email-------------------------------------------- 
-	def send_emails(self, email=[], subject='', message=''):
-		if email:
-			sendmail(email, sender = webnotes.user.name, subject = subject , parts = [['text/html', message]])
-			msgprint("Mail Sent")
-			self.add_in_follow_up(message,'Email')
-
-#-------------------------Checking Sent Mails Details----------------------------------------------				
-	def send_mail(self):
-		if not self.doc.subject or not self.doc.message:
-			msgprint("Please enter subject & message in their respective fields.")
-		elif not self.doc.email_id:
-			msgprint("Recipient not specified. Please add email id of lead in 'Email id' field provided in 'Contact Info' section.")
-			raise Exception
-		else :
-		 self.send_emails([self.doc.email_id.strip(' ')], subject = self.doc.subject ,message = self.doc.message)
-
-#---------------------- Add details in follow up table----------------
 	def add_in_follow_up(self,message,type):
 		import datetime
 		child = addchild( self.doc, 'follow_up', 'Communication Log', 1, self.doclist)
diff --git a/erpnext/selling/doctype/lead/lead.txt b/erpnext/selling/doctype/lead/lead.txt
index b6aa839..a467f3a 100644
--- a/erpnext/selling/doctype/lead/lead.txt
+++ b/erpnext/selling/doctype/lead/lead.txt
@@ -3,9 +3,9 @@
 
 	# These values are common in all dictionaries
 	{
-		'creation': '2012-05-15 12:14:52',
+		'creation': '2012-06-05 20:03:20',
 		'docstatus': 0,
-		'modified': '2012-05-30 12:43:03',
+		'modified': '2012-08-02 18:01:53',
 		'modified_by': u'Administrator',
 		'owner': u'Administrator'
 	},
@@ -507,23 +507,6 @@
 
 	# DocField
 	{
-		'colour': u'White:FFF',
-		'description': u'Probability of lead converting to customer',
-		'doctype': u'DocField',
-		'fieldname': u'rating',
-		'fieldtype': u'Select',
-		'in_filter': 1,
-		'label': u'Rating',
-		'oldfieldname': u'rating',
-		'oldfieldtype': u'Select',
-		'options': u'\nHot\nWarm\nCold',
-		'permlevel': 0,
-		'reqd': 0,
-		'search_index': 0
-	},
-
-	# DocField
-	{
 		'default': u'__user',
 		'doctype': u'DocField',
 		'fieldname': u'lead_owner',
@@ -694,5 +677,14 @@
 		'oldfieldtype': u'Small Text',
 		'permlevel': 1,
 		'print_hide': 1
+	},
+
+	# DocField
+	{
+		'doctype': u'DocField',
+		'fieldname': u'unsubscribed',
+		'fieldtype': u'Check',
+		'label': u'Unsubscribed',
+		'permlevel': 0
 	}
 ]
\ No newline at end of file
diff --git a/erpnext/selling/doctype/lead/lead_list.js b/erpnext/selling/doctype/lead/lead_list.js
index ca18dc6..b876d52 100644
--- a/erpnext/selling/doctype/lead/lead_list.js
+++ b/erpnext/selling/doctype/lead/lead_list.js
@@ -4,8 +4,7 @@
 		this.fields = this.fields.concat([
 			'tabLead.lead_name',
 			'tabLead.status',
-			'tabLead.source',
-			'tabLead.rating'
+			'tabLead.source'
 		]);
 		this.stats = this.stats.concat(['status', 'source', 'rating', 'company']);
 	},
diff --git a/erpnext/selling/doctype/opportunity/opportunity.py b/erpnext/selling/doctype/opportunity/opportunity.py
index 1bcde25..20dcef3 100644
--- a/erpnext/selling/doctype/opportunity/opportunity.py
+++ b/erpnext/selling/doctype/opportunity/opportunity.py
@@ -197,118 +197,7 @@
 			set(self.doc, 'status', 'Opportunity Lost')
 			set(self.doc, 'order_lost_reason', arg)
 			return 'true'
-		
-		
-	# On Send Email
-	# ====================================================================================================================
-	#def send_emails(self,email,sender,subject,message):
-	#	if email:
-	#		sendmail(email,sender,subject=subject or 'Opportunity',parts=[['text/plain',message or self.get_enq_summary()]])
-
-	# Prepare HTML Table and Enter Opportunity Items in it, which will be added in enq summary
-	# ====================================================================================================================
-	def quote_table(self):
-		if getlist(self.doclist,'enq_details'):
-			header_lbl = ['Item Code','Item Name','Description','Reqd Qty','UOM']
-			item_tbl = '''<table style="width:90%%; border:1px solid #AAA; border-collapse:collapse"><tr>'''
-			for i in header_lbl:
-				item_header = '''<td style="width=20%%; border:1px solid #AAA; border-collapse:collapse;"><b>%s</b></td>''' % i
-				item_tbl += item_header
-			item_tbl += '''</tr>'''
-			
-			for d in getlist(self.doclist,'enq_details'):
-				item_det = '''
-					<tr><td style="width:20%%; border:1px solid #AAA; border-collpase:collapse">%s</td>
-					<td style="width:20%%; border:1px solid #AAA; border-collapse:collpase">%s</td>
-					<td style="width:20%%; border:1px solid #AAA; border-collapse:collpase">%s</td>
-					<td style="width:20%%; border:1px solid #AAA; border-collapse:collpase">%s</td>
-					<td style="width:20%%; border:1px solid #AAA; border-collapse:collpase">%s</td></tr>
-				''' % (d.item_code,d.item_name,d.description,d.reqd_qty,d.uom)
-				item_tbl += item_det
-			item_tbl += '''</table>'''
-			return item_tbl
-			
-	# Prepare HTML Page containing summary of Opportunity, which will be sent as message in E-mail
-	# ====================================================================================================================
-	def get_enq_summary(self):
-
-		t = """
-				<html><head></head>
-				<body>
-					<div style="border:1px solid #AAA; padding:20px; width:100%%">
-						<div style="text-align:center;font-size:14px"><b>Request For Quotation</b><br></div>
-						<div style="text-align:center;font-size:12px"> %(from_company)s</div>
-						<div style="text-align:center; font-size:10px"> %(company_address)s</div>
-						<div style="border-bottom:1px solid #AAA; padding:10px"></div> 
-						
-						<div style="padding-top:10px"><b>Quotation Items</b></div>
-						<div><table style="width:100%%">
-						<tr><td style="width:40%%">Opportunity No:</td> <td style="width:60%%"> %(name)s</td></tr>
-						<tr><td style="width:40%%">Opening Date:</td> <td style="width:60%%"> %(transaction_date)s</td></tr>
-						<tr><td style="width:40%%">Expected By Date:</td> <td style="width:60%%"> %(expected_date)s</td></tr>
-						</table>
-						</div>
-						
-						<div style="padding-top:10px"><b>Terms and Conditions</b></div>
-						<div> %(terms_and_conditions)s</div>
-						
-						<div style="padding-top:10px"><b>Contact Details</b></div>
-						<div><table style="width:100%%">
-						<tr><td style="width=40%%">Contact Person:</td><td style="width:60%%"> %(contact_person)s</td></tr>
-						<tr><td style="width=40%%">Contact No:</td><td style="width:60%%"> %(contact_no)s</td></tr>
-						<tr><td style="width=40%%">Email:</td><td style="width:60%%"> %(email)s</td></tr>
-						</table></div>
-						""" % (self.doc.fields)
-		
-		t += """<br><div><b>Quotation Items</b><br></div><div style="width:100%%">%s</div>
-						<br>
-To login into the system, use link : <div><a href='http://67.205.111.118/v160/login.html' target='_blank'>http://67.205.111.118/v160/login.html</a></div><br><br>
-						</div>
-					</body>
-					</html>
-					""" % (self.quote_table())
-		return t
-			
-	#-----------------Email-------------------------------------------- 
-	# ====================================================================================================================
-	def send_emails(self, email=[], subject='', message=''):
-		if email:
-			sender_email= sql("Select email from `tabProfile` where name='%s'"%session['user'])
-			if sender_email and sender_email[0][0]:
-				attach_list=[]
-				for at in getlist(self.doclist,'enquiry_attachment_detail'):
-					if at.select_file:
-						attach_list.append(at.select_file)
-				cc_list=[]
-				if self.doc.cc_to:
-					for cl in (self.doc.cc_to.split(',')):
-						if not validate_email_add(cl.strip(' ')):
-							msgprint('error:%s is not a valid email id' % cl.strip(' '))
-							raise Exception
-						cc_list.append(cl.strip(' ')) 
-						sendmail(cc_list, sender=sender_email[0][0], subject=subject, parts=[['text/html', message]], attach=attach_list)					 
-				sendmail(email, sender=sender_email[0][0], subject=subject, parts=[['text/html', message]], cc=cc_list, attach=attach_list)
-				#sendmail(cc_list, sender = sender_email[0][0], subject = subject , parts = [['text/html', message]],attach=attach_list)
-				msgprint("Mail has been sent")
-				self.add_in_follow_up(message,'Email')
-			else:
-				msgprint("Please enter your mail id in Profile")
-				raise Exception
-	
-	#-------------------------Checking Sent Mails Details----------------------------------------------
-	# ====================================================================================================================
-	def sent_mail(self):
-		if not self.doc.subject or not self.doc.message:
-			msgprint("Please enter subject & message in their respective fields.")
-		elif not self.doc.email_id1:
-			msgprint("Recipient not specified. Please add email id in 'Send To'.")
-			raise Exception
-		else :
-			if not validate_email_add(self.doc.email_id1.strip(' ')):
-				msgprint('error:%s is not a valid email id' % self.doc.email_id1)
-			else:
-				self.send_emails([self.doc.email_id1.strip(' ')], subject = self.doc.subject ,message = self.doc.message)
-
+					
 	#---------------------- Add details in follow up table----------------
 	# ====================================================================================================================
 	def add_in_follow_up(self,message,type):
diff --git a/erpnext/setup/doctype/email_digest/email_digest.py b/erpnext/setup/doctype/email_digest/email_digest.py
index 1e382d1..ac0f378 100644
--- a/erpnext/setup/doctype/email_digest/email_digest.py
+++ b/erpnext/setup/doctype/email_digest/email_digest.py
@@ -415,7 +415,6 @@
 
 		from webnotes.utils.email_lib import sendmail
 		try:
-			#webnotes.msgprint('in send')
 			sendmail(
 				recipients=recipient_list,
 				sender='notifications+email_digest@erpnext.com',
diff --git a/erpnext/setup/doctype/email_settings/email_settings.py b/erpnext/setup/doctype/email_settings/email_settings.py
index 118dba2..cb28657 100644
--- a/erpnext/setup/doctype/email_settings/email_settings.py
+++ b/erpnext/setup/doctype/email_settings/email_settings.py
@@ -24,44 +24,24 @@
 		self.doc,self.doclist = doc,doclist
 
 	def validate(self):
-		"""
-			Checks connectivity to email servers before saving
-		"""
+		"""Checks connectivity to email servers before saving"""
 		self.validate_outgoing()
 		self.validate_incoming()
 
-	
 	def validate_outgoing(self):
-		"""
-			Checks incoming email settings
-		"""
+		"""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
+			from webnotes.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 smtp_connect
-			sess = out_email.smtp_connect()
-			
-			try:
-				sess.quit()
-			except:
-				pass
-		
+			# exceptions are handled in session connect
+			sess = smtpserver.sess
 
 	def validate_incoming(self):
 		"""
diff --git a/erpnext/startup/schedule_handlers.py b/erpnext/startup/schedule_handlers.py
index a828fea..021cb1f 100644
--- a/erpnext/startup/schedule_handlers.py
+++ b/erpnext/startup/schedule_handlers.py
@@ -24,27 +24,26 @@
 		* get support email
 		* recurring invoice
 	"""
-	try:
-		from support.doctype.support_ticket import get_support_mails
-		get_support_mails()
-	except Exception, e:
-		scheduler.log('get_support_mails')
+	# pull emails
+	from support.doctype.support_ticket import get_support_mails
+	run_fn(get_support_mails)
 
-	try:
-		from accounts.doctype.gl_control.gl_control import manage_recurring_invoices
-		manage_recurring_invoices()
-	except Exception, e:
-		scheduler.log('manage_recurring_invoices')
-
+	# run recurring invoices
+	from accounts.doctype.gl_control.gl_control import manage_recurring_invoices
+	run_fn(manage_recurring_invoices)
 	
+	# bulk email
+	from webnotes.utils.email_lib.bulk import flush
+	run_fn(flush)
 	
 def execute_daily():
-	"""email digest"""
-	try:
-		from setup.doctype.email_digest.email_digest import send
-		send()
-	except Exception, e:
-		scheduler.log('email_digest.send')
+	# email digest
+	from setup.doctype.email_digest.email_digest import send
+	run_fn(send)
+
+	# send bulk emails
+	from webnotes.utils.email_lib.bulk import cleanup
+	run_fn(clear_outbox)
 
 def execute_weekly():
 	pass
@@ -54,3 +53,9 @@
 
 def execute_hourly():
 	pass
+	
+def run_fn(fn):
+	try:
+		fn()
+	except Exception, e:
+		scheduler.log(fn.func_name)
diff --git a/erpnext/stock/doctype/item/item.py b/erpnext/stock/doctype/item/item.py
index 9864fc9..9e00dc1 100644
--- a/erpnext/stock/doctype/item/item.py
+++ b/erpnext/stock/doctype/item/item.py
@@ -181,27 +181,6 @@
 				self.doc.is_asset_item = 'No'
 				raise Exception
 
-	def check_min_inventory_level(self):
-		if self.doc.minimum_inventory_level:
-			total_qty = sql("select sum(projected_qty) from tabBin where item_code = %s",self.doc.name)
-			if flt(total_qty) < flt(self.doc.minimum_inventory_level):
-				msgprint("Your minimum inventory level is reached")
-				send_to = []
-				send = sql("select t1.email from `tabProfile` t1,`tabUserRole` t2 where t2.role IN ('Material Master Manager','Purchase Manager') and t2.parent = t1.name")
-				for d in send:
-					send_to.append(d[0])
-				msg = '''
-Minimum Inventory Level Reached
-
-Item Code: %s
-Item Name: %s
-Minimum Inventory Level: %s
-Total Available Qty: %s
-
-''' % (self.doc.item_code, self.doc.item_name, self.doc.minimum_inventory_level, total_qty)
-
-				sendmail(send_to, sender='automail@webnotestech.com', subject='Minimum Inventory Level Reached', parts=[['text/plain', msg]])
-
 	def get_file_details(self, arg = ''):
 		file = sql("select file_group, description from tabFile where name = %s", eval(arg)['file_name'], as_dict = 1)
 
diff --git a/erpnext/utilities/doctype/contact/contact.txt b/erpnext/utilities/doctype/contact/contact.txt
index 135699b..baa2a77 100644
--- a/erpnext/utilities/doctype/contact/contact.txt
+++ b/erpnext/utilities/doctype/contact/contact.txt
@@ -3,9 +3,9 @@
 
 	# These values are common in all dictionaries
 	{
-		'creation': '2012-07-02 19:57:48',
+		'creation': '2012-07-03 14:22:38',
 		'docstatus': 0,
-		'modified': '2012-07-03 12:54:52',
+		'modified': '2012-08-02 13:16:48',
 		'modified_by': u'Administrator',
 		'owner': u'Administrator'
 	},
@@ -38,133 +38,12 @@
 		'parenttype': u'DocType'
 	},
 
-	# These values are common for all DocPerm
-	{
-		'doctype': u'DocPerm',
-		'name': '__common__',
-		'parent': u'Contact',
-		'parentfield': u'permissions',
-		'parenttype': u'DocType',
-		'read': 1
-	},
-
 	# DocType, Contact
 	{
 		'doctype': 'DocType',
 		'name': u'Contact'
 	},
 
-	# DocPerm
-	{
-		'cancel': 1,
-		'create': 1,
-		'doctype': u'DocPerm',
-		'permlevel': 0,
-		'role': u'System Manager',
-		'write': 1
-	},
-
-	# DocPerm
-	{
-		'amend': 0,
-		'cancel': 1,
-		'create': 1,
-		'doctype': u'DocPerm',
-		'permlevel': 0,
-		'role': u'Sales Master Manager',
-		'submit': 0,
-		'write': 1
-	},
-
-	# DocPerm
-	{
-		'cancel': 1,
-		'create': 1,
-		'doctype': u'DocPerm',
-		'permlevel': 0,
-		'role': u'Purchase Master Manager',
-		'write': 1
-	},
-
-	# DocPerm
-	{
-		'create': 1,
-		'doctype': u'DocPerm',
-		'permlevel': 0,
-		'role': u'Sales Manager',
-		'write': 1
-	},
-
-	# DocPerm
-	{
-		'create': 1,
-		'doctype': u'DocPerm',
-		'permlevel': 0,
-		'role': u'Purchase Manager',
-		'write': 1
-	},
-
-	# DocPerm
-	{
-		'create': 1,
-		'doctype': u'DocPerm',
-		'permlevel': 0,
-		'role': u'Maintenance Manager',
-		'write': 1
-	},
-
-	# DocPerm
-	{
-		'create': 1,
-		'doctype': u'DocPerm',
-		'permlevel': 0,
-		'role': u'Accounts Manager',
-		'write': 1
-	},
-
-	# DocPerm
-	{
-		'create': 1,
-		'doctype': u'DocPerm',
-		'permlevel': 0,
-		'role': u'Sales User',
-		'write': 1
-	},
-
-	# DocPerm
-	{
-		'create': 1,
-		'doctype': u'DocPerm',
-		'permlevel': 0,
-		'role': u'Purchase User',
-		'write': 1
-	},
-
-	# DocPerm
-	{
-		'create': 1,
-		'doctype': u'DocPerm',
-		'permlevel': 0,
-		'role': u'Maintenance User',
-		'write': 1
-	},
-
-	# DocPerm
-	{
-		'create': 1,
-		'doctype': u'DocPerm',
-		'permlevel': 0,
-		'role': u'Accounts User',
-		'write': 1
-	},
-
-	# DocPerm
-	{
-		'doctype': u'DocPerm',
-		'permlevel': 1,
-		'role': u'All'
-	},
-
 	# DocField
 	{
 		'colour': u'White:FFF',
@@ -359,6 +238,15 @@
 	# DocField
 	{
 		'doctype': u'DocField',
+		'fieldname': u'unsubscribed',
+		'fieldtype': u'Check',
+		'label': u'Unsubscribed',
+		'permlevel': 0
+	},
+
+	# DocField
+	{
+		'doctype': u'DocField',
 		'fieldname': u'trash_reason',
 		'fieldtype': u'Small Text',
 		'label': u'Trash Reason',
diff --git a/erpnext/website/doctype/blog_subscriber/__init__.py b/erpnext/website/doctype/blog_subscriber/__init__.py
deleted file mode 100644
index e69de29..0000000
--- a/erpnext/website/doctype/blog_subscriber/__init__.py
+++ /dev/null
diff --git a/erpnext/website/doctype/blog_subscriber/blog_subscriber.txt b/erpnext/website/doctype/blog_subscriber/blog_subscriber.txt
deleted file mode 100644
index 1fa8223..0000000
--- a/erpnext/website/doctype/blog_subscriber/blog_subscriber.txt
+++ /dev/null
@@ -1,29 +0,0 @@
-# DocType, Blog Subscriber
-[
-
-	# These values are common in all dictionaries
-	{
-		'creation': '2012-03-27 14:36:47',
-		'docstatus': 0,
-		'modified': '2012-03-27 14:36:47',
-		'modified_by': u'Administrator',
-		'owner': u'Administrator'
-	},
-
-	# These values are common for all DocType
-	{
-		'colour': u'White:FFF',
-		'doctype': 'DocType',
-		'module': u'Website',
-		'name': '__common__',
-		'section_style': u'Simple',
-		'show_in_menu': 0,
-		'version': 1
-	},
-
-	# DocType, Blog Subscriber
-	{
-		'doctype': 'DocType',
-		'name': u'Blog Subscriber'
-	}
-]
\ No newline at end of file
diff --git a/erpnext/website/page/unsubscribe/__init__.py b/erpnext/website/page/unsubscribe/__init__.py
deleted file mode 100644
index e69de29..0000000
--- a/erpnext/website/page/unsubscribe/__init__.py
+++ /dev/null
diff --git a/erpnext/website/page/unsubscribe/unsubscribe.html b/erpnext/website/page/unsubscribe/unsubscribe.html
deleted file mode 100644
index 7b2b68e..0000000
--- a/erpnext/website/page/unsubscribe/unsubscribe.html
+++ /dev/null
@@ -1,13 +0,0 @@
-<div class="layout_wrapper">
-	<div class="web-content">
-		<h1>Unsubscribe</h1>
-		<br>
-		<div class="web-main-section">
-			<input name="unsubscribe">
-			<button class="btn" id="btn-unsubscribe">Unsubscribe</button>
-		</div>
-		<div class="web-side-section">
-		</div>
-		<div style="clear: both"></div>
-	</div>
-</div>
\ No newline at end of file
diff --git a/erpnext/website/page/unsubscribe/unsubscribe.js b/erpnext/website/page/unsubscribe/unsubscribe.js
deleted file mode 100644
index 9e83020..0000000
--- a/erpnext/website/page/unsubscribe/unsubscribe.js
+++ /dev/null
@@ -1,37 +0,0 @@
-// ERPNext - web based ERP (http://erpnext.com)
-// Copyright (C) 2012 Web Notes Technologies Pvt Ltd
-// 
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-// 
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-// 
-// You should have received a copy of the GNU General Public License
-// along with this program.  If not, see <http://www.gnu.org/licenses/>.
-
-pscript.onload_unsubscribe = function(wrapper) {
-	var email = window.location.hash.split('/').splice(-1);
-	$(wrapper).find('input[name="unsubscribe"]').val(email)
-	
-	$('#btn-unsubscribe').click(function() {
-		var email = $(wrapper).find('input[name="unsubscribe"]').val();
-		if(email) {
-			var btn = this;
-			wn.call({
-				module:'website',
-				page:'unsubscribe',
-				method:'unsubscribe',
-				args:email,
-				btn: this,
-				callback: function() {
-					$(wrapper).find('input[name="unsubscribe"]').val('');
-				}
-			});
-		}
-	});
-}
\ No newline at end of file
diff --git a/erpnext/website/page/unsubscribe/unsubscribe.py b/erpnext/website/page/unsubscribe/unsubscribe.py
deleted file mode 100644
index 9985ded..0000000
--- a/erpnext/website/page/unsubscribe/unsubscribe.py
+++ /dev/null
@@ -1,26 +0,0 @@
-# ERPNext - web based ERP (http://erpnext.com)
-# Copyright (C) 2012 Web Notes Technologies Pvt Ltd
-# 
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-# 
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-# 
-# You should have received a copy of the GNU General Public License
-# along with this program.  If not, see <http://www.gnu.org/licenses/>.
-
-import webnotes
-
-@webnotes.whitelist()
-def unsubscribe(arg):
-	"""unsubscribe from lists"""
-	lists = [['Blog Subscriber', 'name']]
-	for l in lists:
-		webnotes.conn.sql("""delete from `tab%s` where %s=%s""" % (l[0], l[1], '%s'), arg)
-		
-	webnotes.msgprint('Unsubscribed!')
\ No newline at end of file
diff --git a/erpnext/website/page/unsubscribe/unsubscribe.txt b/erpnext/website/page/unsubscribe/unsubscribe.txt
deleted file mode 100644
index 2cc3b58..0000000
--- a/erpnext/website/page/unsubscribe/unsubscribe.txt
+++ /dev/null
@@ -1,43 +0,0 @@
-# Page, unsubscribe
-[
-
-	# These values are common in all dictionaries
-	{
-		'creation': '2012-01-27 17:19:02',
-		'docstatus': 0,
-		'modified': '2012-01-27 17:19:02',
-		'modified_by': 'Administrator',
-		'owner': 'Administrator'
-	},
-
-	# These values are common for all Page
-	{
-		'doctype': 'Page',
-		'module': 'Website',
-		'name': '__common__',
-		'page_name': 'unsubscribe',
-		'standard': 'Yes',
-		'title': 'Unsubscribe'
-	},
-
-	# These values are common for all Page Role
-	{
-		'doctype': 'Page Role',
-		'name': '__common__',
-		'parent': 'unsubscribe',
-		'parentfield': 'roles',
-		'parenttype': 'Page',
-		'role': 'Guest'
-	},
-
-	# Page, unsubscribe
-	{
-		'doctype': 'Page',
-		'name': 'unsubscribe'
-	},
-
-	# Page Role
-	{
-		'doctype': 'Page Role'
-	}
-]
\ No newline at end of file
diff --git a/erpnext/website/templates/pages/unsubscribed.html b/erpnext/website/templates/pages/unsubscribed.html
new file mode 100644
index 0000000..3dc7df9
--- /dev/null
+++ b/erpnext/website/templates/pages/unsubscribed.html
@@ -0,0 +1,11 @@
+{% extends "html/outer.html" %}
+
+{% block content %}
+<div class="content">
+	<div class="layout-wrapper layout-main">
+		<h3>Unsubscribed</h3>
+		<br>
+		<p><b>{{ webnotes.unsubscribed_email }}</b> has been unsubscribed.</p>
+	</div>
+</div>
+{% endblock %}
\ No newline at end of file
diff --git a/erpnext/website/utils.py b/erpnext/website/utils.py
index 22fcce7..470dbd7 100644
--- a/erpnext/website/utils.py
+++ b/erpnext/website/utils.py
@@ -41,3 +41,37 @@
 	name = title.lower()
 	name = re.sub('[~!@#$%^&*()<>,."\']', '', name)
 	return '-'.join(name.split()[:4])
+
+def render(page_name):
+	"""render html page"""
+	import webnotes
+	try:
+		if page_name:
+			html = get_html(page_name)
+		else:
+			html = get_html('index')
+	except Exception, e:
+		html = get_html('404')
+
+	print "Content-Type: text/html"
+	print
+	print html.encode('utf-8')
+	
+def get_html(page_name):
+	"""get page html"""
+	page_name = scrub_page_name(page_name)
+	comments = get_comments(page_name)
+	
+	import website.web_cache
+	html = website.web_cache.get_html(page_name, comments)
+	return html
+
+def get_comments(page_name):
+	import webnotes
+	
+	if page_name == '404':
+		comments = """error: %s""" % webnotes.getTraceback()
+	else:
+		comments = """page: %s""" % page_name
+		
+	return comments	
diff --git a/erpnext/website/web_cache.py b/erpnext/website/web_cache.py
index 893f7f2..e08499b 100644
--- a/erpnext/website/web_cache.py
+++ b/erpnext/website/web_cache.py
@@ -91,6 +91,7 @@
 	return page_list
 
 def prepare_args(page_name):
+	import webnotes
 	if page_name == 'index':
 		page_name = get_home_page()
 
@@ -98,6 +99,7 @@
 		args = {
 			'template': 'pages/%s.html' % page_name,
 			'name': page_name,
+			'webnotes': webnotes
 		}
 	else:
 		args = get_doc_fields(page_name)
diff --git a/public/web.py b/public/web.py
index 34d38fe..dcacfcd 100755
--- a/public/web.py
+++ b/public/web.py
@@ -40,39 +40,8 @@
 
 def respond():
 	import webnotes
-	try:
-		if 'page' in webnotes.form_dict:
-			html = get_html(webnotes.form_dict['page'])
-		else:
-			# show home page
-			html = get_html('index')
-	except Exception, e:
-		html = get_html('404')
-
-	print "Content-Type: text/html"
-	print
-	print html.encode('utf-8')
-
-def get_html(page_name):
 	import website.utils
-	page_name = website.utils.scrub_page_name(page_name)
-	
-	comments = get_comments(page_name)
-	
-	import website.web_cache
-	html = website.web_cache.get_html(page_name, comments)
-	
-	return html
-
-def get_comments(page_name):
-	import webnotes
-	
-	if page_name == '404':
-		comments = """error: %s""" % webnotes.getTraceback()
-	else:
-		comments = """page: %s""" % page_name
-		
-	return comments
+	return website.utils.render(webnotes.form_dict.get('page'))
 
 if __name__=="__main__":
 	init()