From 89aeb2d3241ef7bfa055f92d715283db0f382e5f Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Thu, 11 Jun 2015 00:21:04 -0400 Subject: [PATCH] [fix] Email Account - Checkbox: Always use Account's Email ID as Sender If checked, the sender is replaced with the Email ID mentioned in the Email Account. Used when your email provider does not allow you to send emails from different senders. --- frappe/core/doctype/communication/communication.py | 12 +++++++----- .../email/doctype/email_account/email_account.json | 11 ++++++++++- frappe/email/smtp.py | 5 +++-- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/frappe/core/doctype/communication/communication.py b/frappe/core/doctype/communication/communication.py index 3edd675b17..8163163c18 100644 --- a/frappe/core/doctype/communication/communication.py +++ b/frappe/core/doctype/communication/communication.py @@ -5,7 +5,7 @@ from __future__ import unicode_literals, absolute_import import frappe import json from email.utils import formataddr, parseaddr -from frappe.utils import get_url, get_formatted_email, cstr +from frappe.utils import get_url, get_formatted_email, cstr, cint from frappe.utils.file_manager import get_file import frappe.email.smtp from frappe import _ @@ -61,13 +61,15 @@ class Communication(Document): {"append_to": self.reference_doctype, "enable_incoming": 1}, "email_id") self.outgoing_email_account = frappe.db.get_value("Email Account", - {"append_to": self.reference_doctype, "enable_outgoing": 1}, "email_id") + {"append_to": self.reference_doctype, "enable_outgoing": 1}, + ["email_id", "always_use_account_email_id_as_sender"], as_dict=True) if not self.incoming_email_account: self.incoming_email_account = frappe.db.get_value("Email Account", {"default_incoming": 1}, "email_id") if not self.outgoing_email_account: - self.outgoing_email_account = frappe.db.get_value("Email Account", {"default_outgoing": 1}, "email_id") + self.outgoing_email_account = frappe.db.get_value("Email Account", {"default_outgoing": 1}, + ["email_id", "always_use_account_email_id_as_sender"], as_dict=True) or frappe._dict() def notify(self, print_html=None, print_format=None, attachments=None, except_recipient=False): self.prepare_to_notify(print_html, print_format, attachments) @@ -98,8 +100,8 @@ class Communication(Document): self.set_incoming_outgoing_accounts() - if not self.sender: - self.sender = formataddr([frappe.session.data.full_name or "Notification", self.outgoing_email_account]) + if not self.sender or cint(self.outgoing_email_account.always_use_account_email_id_as_sender): + self.sender = formataddr([frappe.session.data.full_name or "Notification", self.outgoing_email_account.email_id]) self.attachments = [] diff --git a/frappe/email/doctype/email_account/email_account.json b/frappe/email/doctype/email_account/email_account.json index c5ea24aa49..a6879b2af3 100644 --- a/frappe/email/doctype/email_account/email_account.json +++ b/frappe/email/doctype/email_account/email_account.json @@ -291,6 +291,15 @@ "permlevel": 0, "precision": "" }, + { + "depends_on": "enable_outgoing", + "description": "Uses the Email ID mentioned in this Account as the Sender for all emails sent using this Account. ", + "fieldname": "always_use_account_email_id_as_sender", + "fieldtype": "Check", + "label": "Always use Account's Email ID as Sender", + "permlevel": 0, + "precision": "" + }, { "allow_on_submit": 0, "fieldname": "signature_section", @@ -419,7 +428,7 @@ "is_submittable": 0, "issingle": 0, "istable": 0, - "modified": "2015-06-02 07:27:15.596220", + "modified": "2015-06-11 00:16:24.026081", "modified_by": "Administrator", "module": "Email", "name": "Email Account", diff --git a/frappe/email/smtp.py b/frappe/email/smtp.py index a6445714cc..0fbf693095 100644 --- a/frappe/email/smtp.py +++ b/frappe/email/smtp.py @@ -21,8 +21,8 @@ def send(email, append_to=None): try: smtpserver = SMTPServer(append_to=append_to) - if hasattr(smtpserver, "always_use_login_id_as_sender") and \ - cint(smtpserver.always_use_login_id_as_sender) and smtpserver.login: + if hasattr(smtpserver, "always_use_account_email_id_as_sender") and \ + cint(smtpserver.always_use_account_email_id_as_sender) and smtpserver.login: if not email.reply_to: email.reply_to = email.sender email.sender = smtpserver.login @@ -120,6 +120,7 @@ class SMTPServer: self.port = self.email_account.smtp_port self.use_ssl = self.email_account.use_tls self.sender = self.email_account.email_id + self.always_use_account_email_id_as_sender = self.email_account.get("always_use_account_email_id_as_sender") @property def sess(self):