def sendTestMail(self): title = None query = None default = "" dest = self.config.admin_mail if not dest: title = tr('No default recipient') query = tr('contact email address is empty, enter a recipient:') elif not check_mail(dest): title = tr('contact email address is invalid') query = tr('Fix contact email address:') default = dest if title is not None: dest, validated = QInputDialog.getText(self, title, query, QLineEdit.Normal, default) dest = unicode(dest) if not validated: self.mainwindow.addToInfoArea(tr('email sending was cancelled')) return elif not check_mail(dest): QMessageBox.warning(self, tr('Test cancelled'), tr("Invalid contact email address '%s'") % dest) return else: self.setAdminMail(dest) self.admin_mail.setText(dest) # Used if user leave Sender mail empty if len(self.config.sender_mail) == 0: self.setSenderMail(self.config.admin_mail) self.sender_mail.setText(self.config.admin_mail) self.sender_mail.validColor() self.client.call("contact", 'sendTestMail', self.config.sender_mail, dest) self.mainwindow.addToInfoArea(tr("test email was sent to '%s'") % dest)
def sendMailToAdmin_cb(self, unused, template_variables): template_variables['my_fqdn'] = '%s.%s' % ( template_variables['my_hostname'], template_variables['my_domain']) jinja_env = jinja.Environment() template = jinja_env.from_string(self.body_template) rendered_body = unicode(template.render(**template_variables)) msg = MIMEText(rendered_body.encode('utf-8'), 'plain', 'utf-8') msg['Subject'] = u'[EW4 %s] %s' % ( template_variables['my_hostname'], unicode(template_variables['subject'])) sender = self.config.sender_mail if check_mail(sender): msg['From'] = sender else: raise NuConfError(CONTACT_INVALID_SENDER, tr("'sender' e-mail : invalid e-mail address")) recipient = self.config.admin_mail if check_mail(recipient): msg['To'] = recipient else: raise NuConfError(CONTACT_INVALID_RECIPIENT, tr("'recipient' e-mail : invalid e-mail address")) defer = sendmail('127.0.0.1', sender, recipient, msg.as_string()) defer.addCallback(self.logSuccess) return defer
def isValidWithMsg(self, allow_empty=True): for attr in self.__class__.ATTRS: if getattr(self, attr) is None: return False, "%s is unset" % attr if self.language not in ['en', 'fr']: return False, "unknow language '%s'" % self.language if not(allow_empty and 0 == len(self.admin_mail)): if not check_mail(self.admin_mail): return False, 'Administrator e-mail is invalid' if not(allow_empty and 0 == len(self.sender_mail)): if not check_mail(self.sender_mail): return False, 'sender e-mail is invalid' return True, ''
def service_sendTestMail(self, context, sender=None, recipient=None): """ Send a test email. If sender and/or recipient are not specified, values of current configuration will be used. """ if sender is None: sender = self.config.sender_mail else: sender = sender.strip() if recipient is None: recipient = self.config.admin_mail else: recipient = recipient.strip() # TODO fr / en # add fqdn msg_text = u"""Bonjour, Ce message de test a été envoyé depuis l'interface d'administration d'EdenWall. Si vous l'avez reçu, cela confirme que la configuration en place au moment de l'envoi vous permet de recevoir les messages système (alertes et informations) de votre pare-feu EdenWall.""" if context.isUserContext(): session = context.getSession() msg_text += u"\n\nL'envoi ce de message a été déclenché par une action utilisateur.\nInformations de traçage: %s\n" % (session,) msg = MIMEText(msg_text.encode('ISO-8859-1'), 'plain', 'ISO-8859-1') msg['Subject'] = 'EdenWall : test mail' if check_mail(sender): msg['From'] = sender else: raise NuConfError(CONTACT_INVALID_SENDER, "'sender' e-mail : invalid e-mail address") if check_mail(recipient): msg["To"] = recipient else: raise NuConfError(CONTACT_INVALID_RECIPIENT, "'recipient' e-mail : invalid e-mail address") return self.sendTestMail('127.0.0.1', msg['From'], [msg['To']], msg.as_string())