Skip to content

Commit

Permalink
Merge pull request #178 from gisce/Alow_custom_senders
Browse files Browse the repository at this point in the history
Allow custom senders and move Sender construction in separated functions to easy inheritance
  • Loading branch information
eberloso authored Feb 26, 2025
2 parents 7c8b0d1 + ac8cfc7 commit 3a6bca2
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 3a6bca2

Please sign in to comment.