feat(email): Allow emails to be sent without SMTP authentication by setting (#6816)

* Add email_account option to disable SMTP Authentication.

* Partially reverting email_account.py changes. Unnecessary incoming_server logic was added.

* Codacy code style issue fix.

* Suppress 'Password is required or select Awaiting Password' message if only smtp is used an no athentication is required.

* Suppress 'Password is required or select Awaiting Password' message if only smtp is used an no athentication is required.

* Simplified logic.

* Reverted excessive changes.

* fix: remove description and make label clear
This commit is contained in:
Aleksas Pielikis 2019-01-28 08:52:28 +02:00 committed by Rushabh Mehta
parent c294ee3583
commit ecb3d3f56d
3 changed files with 45 additions and 8 deletions

View file

@ -1130,6 +1130,39 @@
"translatable": 0,
"unique": 0
},
{
"allow_bulk_edit": 0,
"allow_in_quick_entry": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"default": "0",
"fieldname": "no_smtp_authentication",
"fieldtype": "Check",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Disable SMTP server authentication",
"length": 0,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"translatable": 0,
"unique": 0
},
{
"allow_bulk_edit": 0,
"allow_in_quick_entry": 0,
@ -1566,4 +1599,4 @@
"track_changes": 1,
"track_seen": 0,
"track_views": 0
}
}

View file

@ -72,7 +72,7 @@ class EmailAccount(Document):
if self.enable_outgoing:
self.check_smtp()
else:
if self.enable_incoming or self.enable_outgoing:
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:
@ -134,8 +134,9 @@ class EmailAccount(Document):
port = cint(self.smtp_port),
use_tls = cint(self.use_tls)
)
if self.password:
if self.password and not self.no_smtp_authentication:
server.password = self.get_password()
server.sess
def get_incoming_server(self, in_receive=False, email_sync_rule="UNSEEN"):

View file

@ -88,7 +88,7 @@ def get_outgoing_email_account(raise_exception_not_set=True, append_to=None, sen
if email_account:
if email_account.enable_outgoing and not getattr(email_account, 'from_site_config', False):
raise_exception = True
if email_account.smtp_server in ['localhost','127.0.0.1']:
if email_account.smtp_server in ['localhost','127.0.0.1'] or email_account.no_smtp_authentication:
raise_exception = False
email_account.password = email_account.get_password(raise_exception=raise_exception)
email_account.default_sender = email.utils.formataddr((email_account.name, email_account.get("email_id")))
@ -170,11 +170,14 @@ class SMTPServer:
self.email_account = get_outgoing_email_account(raise_exception_not_set=False, append_to=append_to, sender=sender)
if self.email_account:
self.server = self.email_account.smtp_server
self.login = getattr(self.email_account, "login_id", None) or self.email_account.email_id
if self.email_account.ascii_encode_password:
self.password = frappe.safe_encode(self.email_account.password, 'ascii')
self.login = (getattr(self.email_account, "login_id", None) or self.email_account.email_id)
if not self.email_account.no_smtp_authentication:
if self.email_account.ascii_encode_password:
self.password = frappe.safe_encode(self.email_account.password, 'ascii')
else:
self.password = self.email_account.password
else:
self.password = self.email_account.password
self.password = None
self.port = self.email_account.smtp_port
self.use_tls = self.email_account.use_tls
self.sender = self.email_account.email_id