Skip to content

Commit

Permalink
Move Sender construction in separated functions to easy alow custom s…
Browse files Browse the repository at this point in the history
…enders on in inheritance
  • Loading branch information
polsala committed Feb 24, 2025
1 parent 7c8b0d1 commit ac8cfc7
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions poweremail_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,31 @@ def get_ids_from_dict(self, addresses={}):
result['all'].extend(ids_as_list)
return result

def get_not_debug_sender(self, account):
return SMTPSender(
host=account.smtpserver,
port=account.smtpport,
user=account.smtpuname,
passwd=account.smtppass,
tls=account.smtptls,
ssl=account.smtpssl
)

def get_sender(self, account):
sender = (
Sender(
host=account.smtpserver,
port=account.smtpport,
user=account.smtpuname,
passwd=account.smtppass,
tls=account.smtptls,
ssl=account.smtpssl
)
if config.get('debug_mode', False)
else self.get_not_debug_sender(account)
)
return sender

def send_mail(self, cr, uid, ids,
addresses, subject='', body=None, payload=None, context=None):
def create_qreu(headers, payload, **kwargs):
Expand Down Expand Up @@ -596,14 +621,7 @@ def parse_sender(pem_account, pem_addresses):
extra_headers.pop('Organitzation')
# Use sender if debug is set
sender = (Sender if config.get('debug_mode', False) else SMTPSender)
with sender(
host=account.smtpserver,
port=account.smtpport,
user=account.smtpuname,
passwd=account.smtppass,
tls=account.smtptls,
ssl=account.smtpssl
):
with self.get_sender(account): # Returns a Sender context from qreu
mail = Email()
try:
mail = create_qreu(
Expand Down

0 comments on commit ac8cfc7

Please sign in to comment.