Sends an email. @param key: the name of the template used for the mail @param rcpt: the recipient mail address @param **kwargs: all remaining arguments are passed to the template
(self,
key,
rcpt,
config,
messages,
logger,
**kwargs)
| 65 | messages = 'ddserver.interface.message:MessageManager', |
| 66 | logger = 'ddserver.utils.logger:Logger') |
| 67 | def __send(self, |
| 68 | key, |
| 69 | rcpt, |
| 70 | config, |
| 71 | messages, |
| 72 | logger, |
| 73 | **kwargs): |
| 74 | ''' Sends an email. |
| 75 | |
| 76 | @param key: the name of the template used for the mail |
| 77 | @param rcpt: the recipient mail address |
| 78 | @param **kwargs: all remaining arguments are passed to the template |
| 79 | ''' |
| 80 | |
| 81 | # Load the template |
| 82 | template = self.__environment.get_template(key) |
| 83 | |
| 84 | # Open SMTP connection |
| 85 | try: |
| 86 | smtp = smtplib.SMTP(host = config.smtp.host, |
| 87 | port = config.smtp.port, |
| 88 | timeout = 20) |
| 89 | |
| 90 | except: |
| 91 | logger.error('Failed to contact the SMTP server at %s:%s (template %s)' % |
| 92 | config.smtp.host, |
| 93 | config.smtp.port, |
| 94 | key) |
| 95 | raise |
| 96 | |
| 97 | else: |
| 98 | try: |
| 99 | # Send mail |
| 100 | smtp.sendmail(config.contact.email, |
| 101 | [rcpt], |
| 102 | template.render(rcpt = rcpt, |
| 103 | config = config, |
| 104 | **kwargs)) |
| 105 | |
| 106 | except: |
| 107 | logger.error('Failed to send email to %s (template %s)' % |
| 108 | rcpt, |
| 109 | key) |
| 110 | raise |
| 111 | |
| 112 | finally: |
| 113 | # Close SMTP connection |
| 114 | smtp.quit() |
| 115 | |
| 116 | |
| 117 | def to_user(self, |