Merge pull request #1152 from anandpdoshi/email-sender-fix
Email Account - Checkbox: Always use Account's Email ID as Sender
This commit is contained in:
commit
39ff2ed1b8
3 changed files with 20 additions and 8 deletions
|
|
@ -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 = []
|
||||
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue