linotp.lib.emailprovider module

Interface to an EMail provider and implementation of the SMPT email provider

class linotp.provider.emailprovider.IEmailProvider[source]

Bases: object

An abstract class that has to be implemented by ever e-mail provider class

static getConfigMapping()[source]

for dynamic, adaptive config entries we provide the abilty to have dedicated config entries

entries should look like: {

key: (ConfigName, ConfigType)

}

loadConfig(configDict)[source]

If you implement an e-mail provider that does not require configuration entries, then you may leave this method unimplemented.

Parameters:configDict (dict) – A dictionary that contains all configuration entries you defined (e.g. in the linotp.ini file)
provider_type = 'email'
submitMessage(email_to, message, subject=None)[source]

This method has to be implemented by every subclass of IEmailProvider. It will be called to send out the e-mail.

Parameters:
  • email_to (string) – The e-mail address of the recipient
  • message (string) – The message sent to the recipient
Returns:

A tuple of success and a message

Return type:

bool, string

class linotp.provider.emailprovider.SMTPEmailProvider[source]

Bases: linotp.provider.emailprovider.IEmailProvider

Sends e-mail over a SMTP server.

DEFAULT_EMAIL_FROM = 'linotp@example.com'
DEFAULT_EMAIL_SUBJECT = 'Your OTP'
static get_template_root()[source]

get the email provider template root directory

if there is in
‘email_provider_template_root’ in linotp.config defined
Fallback is EMAIL_PROVIDER_TEMPLATE_ROOT
which is ‘/etc/linotp/email_provider_templates’
Returns:the directory where the email provider templates are expected
loadConfig(configDict)[source]

Loads the configuration for this e-mail e-mail provider

Parameters:configDict (dict) – A dictionary that contains all configuration entries you defined (e.g. in the linotp.ini file)
render_message(email_to, subject, message, replacements)[source]

create a text/plain or a template rendered email message

Parameters:
  • email_to – the target email address
  • subject – the subject of the email message could be None
  • message – the given message
  • replacements – a dictionary with replacement key/value pairs
Returns:

the email message body

static render_simple_message(email_to, email_from, subject, message, replacements)[source]

render the email message body based on a simple text message

Parameters:
  • email_to – the target email address
  • subject – the subject of the email message could be None
  • message – the given message
  • replacements – a dictionary with replacement key/value pairs
Returns:

email message body as string

static render_template_message(email_to, email_from, subject, template_message, replacements)[source]

render the email message body based on a template

the template must be of type multipart/alternative and can contain multipart/related content for example imaged which ewra referenced via cid: names

```
Content-Type: multipart/alternative;
boundary=”===============3294676191386143061==”

MIME-Version: 1.0 Subject: ${Subject} From: ${From} To: ${To}

This is a multi-part alternative message in MIME format. –===============3294676191386143061== Content-Type: text/plain; charset=”us-ascii” MIME-Version: 1.0 Content-Transfer-Encoding: 7bit

This is the alternative plain text message. –===============3294676191386143061== Content-Type: multipart/related;

boundary=”===============3984710301122897564==”

MIME-Version: 1.0

–===============3984710301122897564== Content-Type: text/html; charset=”us-ascii” MIME-Version: 1.0 Content-Transfer-Encoding: 7bit

<html>

<body>
<div align=’center’ height=’100%’>
<table width=’40%’ cellpadding=’20px’ bgcolor=”#f1f2f5”>

```

Parameters:
  • email_to
  • email_from
  • subject
  • template_message
  • replacements
Returns:

email message body as string

submitMessage(email_to, message, subject=None, replacements=None)[source]

Sends out the e-mail.

Parameters:
  • email_to (string) – The e-mail address of the recipient
  • message (string) – The message sent to the recipient
  • subject (string) – otional the subject sent to the recipient
Returns:

A tuple of success and a message

Return type:

bool, string