Email Settings split into Outgoing Email Settings and Support Email Settings

This commit is contained in:
Anand Doshi 2014-03-03 20:32:20 +05:30
parent 64f2ccd9e1
commit e30511d315
16 changed files with 222 additions and 272 deletions

View File

@ -48,8 +48,7 @@ data = [
},
{
"type": "doctype",
"name": "Email Settings",
"label": _("Support Email Settings"),
"name": "Support Email Settings",
"description": _("Setup incoming server for support email id. (e.g. support@example.com)")
},
{

View File

@ -48,8 +48,7 @@ data = [
"items": [
{
"type": "doctype",
"name": "Email Settings",
"label": _("Support Email Settings"),
"name": "Support Email Settings",
"description": _("Setup incoming server for support email id. (e.g. support@example.com)")
},
]

View File

@ -25,3 +25,4 @@ erpnext.patches.4_0.fix_contact_address
erpnext.patches.4_0.customer_discount_to_pricing_rule
execute:frappe.db.sql("""delete from `tabWebsite Item Group` where ifnull(item_group, '')=''""")
erpnext.patches.4_0.remove_module_home_pages
erpnext.patches.4_0.split_email_settings

View File

@ -0,0 +1,50 @@
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
def execute():
frappe.reload_doc("core", "doctype", "outgoing_email_settings")
frappe.reload_doc("support", "doctype", "support_email_settings")
email_settings = frappe.bean("Email Settings")
map_outgoing_email_settings(email_settings)
map_support_email_settings(email_settings)
frappe.delete_doc("Doctype", "Email Settings")
def map_outgoing_email_settings(email_settings):
outgoing_email_settings = frappe.bean("Outgoing Email Settings")
for fieldname in (("outgoing_mail_server", "mail_server"),
"use_ssl", "mail_port", "mail_login", "mail_password",
"always_use_login_id_as_sender",
"auto_email_id", "send_print_in_body_and_attachment"):
if isinstance(fieldname, tuple):
from_fieldname, to_fieldname = fieldname
else:
from_fieldname = to_fieldname = fieldname
outgoing_email_settings.doc.fields[to_fieldname] = email_settings.doc.fields.get(from_fieldname)
outgoing_email_settings.save()
def map_support_email_settings(email_settings):
support_email_settings = frappe.bean("Support Email Settings")
for fieldname in ("sync_support_mails", "support_email",
("support_host", "mail_server"),
("support_use_ssl", "use_ssl"),
("support_username", "mail_login"),
("support_password", "mail_password"),
"support_signature", "send_autoreply", "support_autoreply"):
if isinstance(fieldname, tuple):
from_fieldname, to_fieldname = fieldname
else:
from_fieldname = to_fieldname = fieldname
support_email_settings.doc.fields[to_fieldname] = email_settings.doc.fields.get(from_fieldname)
support_email_settings.save()

View File

@ -1 +0,0 @@
Settings for outgoing emails (SMTP), Support Ticket (POP).

View File

@ -1 +0,0 @@
from __future__ import unicode_literals

View File

@ -1,67 +0,0 @@
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
from frappe.utils import cint
class DocType:
def __init__(self,doc,doclist):
self.doc,self.doclist = doc,doclist
def validate(self):
"""Checks connectivity to email servers before saving"""
self.validate_outgoing()
self.validate_incoming()
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
def validate_incoming(self):
"""
Checks support ticket email settings
"""
if self.doc.sync_support_mails and self.doc.support_host:
from frappe.utils.email_lib.receive import POP3Mailbox
from frappe.model.doc import Document
import _socket, poplib
inc_email = Document('Incoming Email Settings')
inc_email.encode()
inc_email.host = self.doc.support_host
inc_email.use_ssl = self.doc.support_use_ssl
try:
err_msg = 'User Name or Support Password missing. Please enter and try again.'
if not (self.doc.support_username and self.doc.support_password):
raise AttributeError, err_msg
inc_email.username = self.doc.support_username
inc_email.password = self.doc.support_password
except AttributeError, e:
frappe.msgprint(err_msg)
raise
pop_mb = POP3Mailbox(inc_email)
try:
pop_mb.connect()
except _socket.error, e:
# Invalid mail server -- due to refusing connection
frappe.msgprint('Invalid POP3 Mail Server. Please rectify and try again.')
raise
except poplib.error_proto, e:
frappe.msgprint('Invalid User Name or Support Password. Please rectify and try again.')
raise

View File

@ -1,188 +0,0 @@
[
{
"creation": "2013-03-25 17:53:21",
"docstatus": 0,
"modified": "2013-12-06 13:12:25",
"modified_by": "Administrator",
"owner": "Administrator"
},
{
"allow_copy": 1,
"allow_email": 1,
"allow_print": 1,
"description": "Email Settings for Outgoing and Incoming Emails.",
"doctype": "DocType",
"icon": "icon-cog",
"in_create": 1,
"issingle": 1,
"module": "Setup",
"name": "__common__"
},
{
"doctype": "DocField",
"name": "__common__",
"parent": "Email Settings",
"parentfield": "fields",
"parenttype": "DocType",
"permlevel": 0
},
{
"create": 1,
"doctype": "DocPerm",
"name": "__common__",
"parent": "Email Settings",
"parentfield": "permissions",
"parenttype": "DocType",
"permlevel": 0,
"read": 1,
"role": "System Manager",
"write": 1
},
{
"doctype": "DocType",
"name": "Email Settings"
},
{
"description": "Set your outgoing mail SMTP settings here. All system generated notifications, emails will go from this mail server. If you are not sure, leave this blank to use ERPNext servers (emails will still be sent from your email id) or contact your email provider.",
"doctype": "DocField",
"fieldname": "outgoing_mails",
"fieldtype": "Section Break",
"label": "Outgoing Mails"
},
{
"description": "SMTP Server (e.g. smtp.gmail.com)",
"doctype": "DocField",
"fieldname": "outgoing_mail_server",
"fieldtype": "Data",
"label": "Outgoing Mail Server"
},
{
"description": "<a href=\"https://en.wikipedia.org/wiki/Transport_Layer_Security\" target=\"_blank\">[?]</a>",
"doctype": "DocField",
"fieldname": "use_ssl",
"fieldtype": "Check",
"label": "Use TLS"
},
{
"description": "If non standard port (e.g. 587)",
"doctype": "DocField",
"fieldname": "mail_port",
"fieldtype": "Int",
"label": "Mail Port"
},
{
"doctype": "DocField",
"fieldname": "cb0",
"fieldtype": "Column Break"
},
{
"description": "Set Login and Password if authentication is required.",
"doctype": "DocField",
"fieldname": "mail_login",
"fieldtype": "Data",
"label": "Login Id"
},
{
"description": "Check this if you want to send emails as this id only (in case of restriction by your email provider).",
"doctype": "DocField",
"fieldname": "always_use_login_id_as_sender",
"fieldtype": "Check",
"label": "Always use above Login Id as sender"
},
{
"doctype": "DocField",
"fieldname": "mail_password",
"fieldtype": "Password",
"label": "Mail Password"
},
{
"description": "System generated mails will be sent from this email id.",
"doctype": "DocField",
"fieldname": "auto_email_id",
"fieldtype": "Data",
"label": "Auto Email Id"
},
{
"default": "1",
"description": "If checked, an email with an attached HTML format will be added to part of the EMail body as well as attachment. To only send as attachment, uncheck this.",
"doctype": "DocField",
"fieldname": "send_print_in_body_and_attachment",
"fieldtype": "Check",
"label": "Send Print in Body and Attachment"
},
{
"description": "To automatically create Support Tickets from your incoming mail, set your POP3 settings here. You must ideally create a separate email id for the erp system so that all emails will be synced into the system from that mail id. If you are not sure, please contact your EMail Provider.",
"doctype": "DocField",
"fieldname": "section_break0",
"fieldtype": "Section Break",
"label": "Incoming / Support Mail Setting"
},
{
"description": "Check this to pull emails from your mailbox",
"doctype": "DocField",
"fieldname": "sync_support_mails",
"fieldtype": "Check",
"label": "Sync Support Mails"
},
{
"description": "Your support email id - must be a valid email - this is where your emails will come!",
"doctype": "DocField",
"fieldname": "support_email",
"fieldtype": "Data",
"label": "Support Email"
},
{
"description": "POP3 mail server (e.g. pop.gmail.com)",
"doctype": "DocField",
"fieldname": "support_host",
"fieldtype": "Data",
"label": "POP3 Mail Server"
},
{
"doctype": "DocField",
"fieldname": "support_use_ssl",
"fieldtype": "Check",
"label": "Use SSL"
},
{
"doctype": "DocField",
"fieldname": "support_username",
"fieldtype": "Data",
"label": "User Name"
},
{
"doctype": "DocField",
"fieldname": "support_password",
"fieldtype": "Password",
"label": "Support Password"
},
{
"doctype": "DocField",
"fieldname": "cb1",
"fieldtype": "Column Break"
},
{
"description": "Signature to be appended at the end of every email",
"doctype": "DocField",
"fieldname": "support_signature",
"fieldtype": "Text",
"label": "Signature"
},
{
"default": "1",
"doctype": "DocField",
"fieldname": "send_autoreply",
"fieldtype": "Check",
"label": "Send Autoreply"
},
{
"description": "Autoreply when a new mail is received",
"doctype": "DocField",
"fieldname": "support_autoreply",
"fieldtype": "Text",
"label": "Custom Autoreply Message"
},
{
"doctype": "DocPerm"
}
]

View File

@ -160,7 +160,7 @@ def set_defaults(args):
hr_settings.doc.emp_created_by = "Naming Series"
hr_settings.save()
email_settings = frappe.bean("Email Settings")
email_settings = frappe.bean("Outgoing Email Settings")
email_settings.doc.send_print_in_body_and_attachment = 1
email_settings.save()

View File

@ -34,7 +34,7 @@ mail_footer = """<div style="padding: 7px; text-align: right; color: #888"><smal
def get_monthly_bulk_mail_limit():
import frappe
# if global settings, then 500 or unlimited
if frappe.db.get_value('Email Settings', None, 'outgoing_mail_server'):
if frappe.db.get_value('Outgoing Email Settings', None, 'mail_server'):
return 999999
else:
return 500

View File

@ -0,0 +1,47 @@
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
# MIT License. See license.txt
# For license information, please see license.txt
from __future__ import unicode_literals
import frappe
class DocType:
def __init__(self, d, dl):
self.doc, self.doclist = d, dl
def validate(self):
"""
Checks support ticket email settings
"""
if self.doc.sync_support_mails and self.doc.mail_server:
from frappe.utils.email_lib.receive import POP3Mailbox
from frappe.model.doc import Document
import _socket, poplib
inc_email = Document('Incoming Email Settings')
inc_email.encode()
inc_email.host = self.doc.mail_server
inc_email.use_ssl = self.doc.use_ssl
try:
err_msg = 'User Name or Support Password missing. Please enter and try again.'
if not (self.doc.mail_login and self.doc.mail_password):
raise AttributeError, err_msg
inc_email.username = self.doc.mail_login
inc_email.password = self.doc.mail_password
except AttributeError, e:
frappe.msgprint(err_msg)
raise
pop_mb = POP3Mailbox(inc_email)
try:
pop_mb.connect()
except _socket.error, e:
# Invalid mail server -- due to refusing connection
frappe.msgprint('Invalid POP3 Mail Server. Please rectify and try again.')
raise
except poplib.error_proto, e:
frappe.msgprint('Invalid User Name or Support Password. Please rectify and try again.')
raise

View File

@ -0,0 +1,111 @@
[
{
"creation": "2014-03-03 19:48:46",
"docstatus": 0,
"modified": "2014-03-03 20:20:34",
"modified_by": "Administrator",
"owner": "Administrator"
},
{
"allow_copy": 1,
"description": "Email Settings for Outgoing and Incoming Emails.",
"doctype": "DocType",
"icon": "icon-cog",
"in_create": 1,
"issingle": 1,
"module": "Support",
"name": "__common__"
},
{
"doctype": "DocField",
"name": "__common__",
"parent": "Support Email Settings",
"parentfield": "fields",
"parenttype": "DocType",
"permlevel": 0
},
{
"create": 1,
"doctype": "DocPerm",
"name": "__common__",
"parent": "Support Email Settings",
"parentfield": "permissions",
"parenttype": "DocType",
"permlevel": 0,
"read": 1,
"role": "System Manager",
"write": 1
},
{
"doctype": "DocType",
"name": "Support Email Settings"
},
{
"description": "Check this to pull emails from your mailbox",
"doctype": "DocField",
"fieldname": "sync_support_mails",
"fieldtype": "Check",
"label": "Sync Support Mails"
},
{
"description": "Your support email id - must be a valid email - this is where your emails will come!",
"doctype": "DocField",
"fieldname": "support_email",
"fieldtype": "Data",
"label": "Support Email"
},
{
"description": "POP3 mail server (e.g. pop.gmail.com)",
"doctype": "DocField",
"fieldname": "mail_server",
"fieldtype": "Data",
"label": "POP3 Mail Server"
},
{
"doctype": "DocField",
"fieldname": "use_ssl",
"fieldtype": "Check",
"label": "Use SSL"
},
{
"doctype": "DocField",
"fieldname": "mail_login",
"fieldtype": "Data",
"label": "User Name"
},
{
"doctype": "DocField",
"fieldname": "mail_password",
"fieldtype": "Password",
"label": "Support Password"
},
{
"doctype": "DocField",
"fieldname": "cb1",
"fieldtype": "Column Break"
},
{
"description": "Signature to be appended at the end of every email",
"doctype": "DocField",
"fieldname": "support_signature",
"fieldtype": "Text",
"label": "Signature"
},
{
"default": "1",
"doctype": "DocField",
"fieldname": "send_autoreply",
"fieldtype": "Check",
"label": "Send Autoreply"
},
{
"description": "Autoreply when a new mail is received",
"doctype": "DocField",
"fieldname": "support_autoreply",
"fieldtype": "Text",
"label": "Custom Autoreply Message"
},
{
"doctype": "DocPerm"
}
]

View File

@ -10,12 +10,12 @@ from frappe.core.doctype.communication.communication import _make
class SupportMailbox(POP3Mailbox):
def setup(self, args=None):
self.email_settings = frappe.doc("Email Settings", "Email Settings")
self.email_settings = frappe.doc("Support Email Settings", "Support Email Settings")
self.settings = args or frappe._dict({
"use_ssl": self.email_settings.support_use_ssl,
"host": self.email_settings.support_host,
"username": self.email_settings.support_username,
"password": self.email_settings.support_password
"use_ssl": self.email_settings.use_ssl,
"host": self.email_settings.mail_server,
"username": self.email_settings.mail_login,
"password": self.email_settings.mail_password
})
def process_message(self, mail):
@ -53,7 +53,7 @@ Original Query:
msg = cstr(response))
def get_support_mails():
if cint(frappe.db.get_value('Email Settings', None, 'sync_support_mails')):
if cint(frappe.db.get_value('Support Email Settings', None, 'sync_support_mails')):
SupportMailbox()
def add_support_communication(subject, content, sender, docname=None, mail=None):

View File

@ -11,7 +11,7 @@ cur_frm.add_fetch("customer", "customer_name", "customer_name")
$.extend(cur_frm.cscript, {
onload: function(doc, dt, dn) {
if(in_list(user_roles,'System Manager')) {
cur_frm.footer.help_area.innerHTML = '<p><a href="#Form/Email Settings/Email Settings">'+frappe._("Email Settings")+'</a><br>\
cur_frm.footer.help_area.innerHTML = '<p><a href="#Form/Support Email Settings/Support Email Settings">'+frappe._("Support Email Settings")+'</a><br>\
<span class="help">'+frappe._("Integrate incoming support emails to Support Ticket")+'</span></p>';
}
},

View File

@ -13,13 +13,13 @@ class DocType(TransactionBase):
self.doclist = doclist
def get_sender(self, comm):
return frappe.db.get_value('Email Settings',None,'support_email')
return frappe.db.get_value('Support Email Settings',None,'support_email')
def get_subject(self, comm):
return '[' + self.doc.name + '] ' + (comm.subject or 'No Subject Specified')
def get_content(self, comm):
signature = frappe.db.get_value('Email Settings',None,'support_signature')
signature = frappe.db.get_value('Support Email Settings',None,'support_signature')
content = comm.content
if signature:
content += '<p>' + signature + '</p>'