linotp.provider.emailprovider package¶
Interface to an EMail provider and implementation of the SMPT email provider
- class linotp.provider.emailprovider.IEmailProvider¶
Bases:
object
An abstract class that has to be implemented by ever e-mail provider class
- DEFAULT_TIMEOUT = 5¶
- static getConfigMapping()¶
for dynamic, adaptive config entries we provide the abilty to have dedicated config entries
entries should look like: {
key: (ConfigName, ConfigType)
}
- loadConfig(configDict)¶
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 a linotp.cfg file)
- provider_type = 'email'¶
- submitMessage(email_to, message, subject=None)¶
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¶
Bases:
IEmailProvider
Sends e-mail over a SMTP server.
- DEFAULT_EMAIL_FROM = 'linotp@example.com'¶
- DEFAULT_EMAIL_SUBJECT = 'Your OTP'¶
- static get_template_root()¶
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)¶
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 a linotp.cfg file)
- render_message(email_to, subject, message, replacements)¶
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)¶
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)¶
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)¶
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