[fix] bulk.py: always_use_account_email_id_as_sender

This commit is contained in:
Anand Doshi 2016-01-25 13:04:43 +05:30
parent 718a3e629d
commit 9d9e2992b4
2 changed files with 10 additions and 6 deletions

View file

@ -260,6 +260,7 @@ def flush(from_test=False):
try:
if not from_test:
smtpserver.setup_email_account(email.reference_doctype)
smtpserver.replace_sender_in_email(email)
smtpserver.sess.sendmail(email["sender"], email["recipient"], encode(email["message"]))
frappe.db.sql("""update `tabBulk Email` set status='Sent' where name=%s""",

View file

@ -22,12 +22,7 @@ def send(email, append_to=None):
try:
smtpserver = SMTPServer(append_to=append_to)
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
smtpserver.replace_sender_in_email(email)
smtpserver.sess.sendmail(email.sender, email.recipients + (email.cc or []),
email.as_string())
@ -129,6 +124,13 @@ class SMTPServer:
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")
def replace_sender_in_email(self, email):
if hasattr(self, "always_use_account_email_id_as_sender") and \
cint(self.always_use_account_email_id_as_sender) and self.login:
if not email.reply_to:
email.reply_to = email.sender
email.sender = self.login
@property
def sess(self):
"""get session"""
@ -177,3 +179,4 @@ class SMTPServer:
except smtplib.SMTPException:
frappe.msgprint(_('Unable to send emails at this time'))
raise