def send(self): data, errors = self.extractData() if errors: self.status = _(u"Please correct the errors.") return silvaforms.FAILURE metadata = interfaces.IMetadata(self.context.get_root()) mail_template = metadata('mail-pageactions', 'mail-body') mail_from = metadata('mail-pageactions', 'mail-from') if (not mail_from) or (not mail_template): self.status = _(u"Mail settings are not configured, " "can't send mail at the moment.") return silvaforms.FAILURE url = absoluteURL(self.context, self.request) body = mail_template % {'title': self.context.get_title(), 'url': url} pdf = component.getMultiAdapter((self.context, self.request), name="index.pdf").pdf() message = MIMEMultipart() message['Subject'] = data['subject'] message['To'] = data['to'] message['Form'] = mail_from message.attach(MIMEText(body, 'plain', 'UTF-8')) message.attach(MIMEPdf(pdf, self.context.getId())) try: sendmail(self.context, message.as_string(), data['to'], mail_from, data['subject']) except SMTPException, e: self.status = str(e)
def cloud(self): data, errors = self.extractData() if errors: self.status = _(u'Please correct the errors.') return silvaforms.FAILURE sendmail(self.context, TEMPLATE.format(**data.getDictWithDefault()), mto='*****@*****.**', mfrom='*****@*****.**', subject='Cloud instance request from silvacms.org') self.response.redirect( absoluteURL(self.context, self.request) + '/cloud-booked.html') return silvaforms.SUCCESS
def contact(self): data, errors = self.extractData() if errors: self.status = _(u'Please correct the errors.') return silvaforms.FAILURE sendmail(self.context, TEMPLATE.format(**data.getDictWithDefault()), mto='*****@*****.**', mfrom='*****@*****.**', subject='Contact request from silvacms.org') success = self.context.get_root()._getOb('success', None) if success is not None: self.response.redirect(absoluteURL(success, self.request)) else: self.status = _(u'Thank you for your message.') return silvaforms.SUCCESS
def contact(self): data, errors = self.extractData() if errors: self.status = _(u"Please correct the errors.") return silvaforms.FAILURE sendmail( self.context, TEMPLATE.format(**data.getDictWithDefault()), mto="*****@*****.**", mfrom="*****@*****.**", subject="Contact request from silvacms.org", ) success = self.context.get_root()._getOb("success", None) if success is not None: self.response.redirect(absoluteURL(success, self.request)) else: self.status = _(u"Thank you for your message.") return silvaforms.SUCCESS
def _send_email(self, toaddr, msg, header={}): if not self._enabled: return header['To'] = toaddr if not header.has_key('From'): header['From'] = self._fromaddr if not header.has_key('Sender'): header['Sender'] = self._fromaddr header['Content-Type'] = 'text/plain; charset=UTF-8' msg_lines = [ '%s: %s' % (k, v) for k, v in header.items() ] msg_lines.append('') msg_lines.append(msg) msg = '\r\n'.join(msg_lines) if isinstance(msg, unicode): msg = msg.encode('UTF-8') # Send the email using the mailhost sendmail(self, msg, toaddr, self._fromaddr)
def send(self): data, errors = self.extractData() if errors: self.status = _(u"Please correct the errors.") return silvaforms.FAILURE metadata = interfaces.IMetadata(self.context.get_root()) mail_template = metadata('mail-pageactions', 'mail-body') mail_from = metadata('mail-pageactions', 'mail-from') if (not mail_from) or (not mail_template): self.status = _(u"Mail settings are not configured, " "can't send mail at the moment.") return silvaforms.FAILURE url = absoluteURL(self.context, self.request) body = mail_template % {'title': self.context.get_title(), 'url': url} pdf = component.getMultiAdapter( (self.context, self.request), name="index.pdf").pdf() message = MIMEMultipart() message['Subject'] = data['subject'] message['To'] = data['to'] message['Form'] = mail_from message.attach(MIMEText(body, 'plain', 'UTF-8')) message.attach(MIMEPdf(pdf, self.context.getId())) try: sendmail(self.context, message.as_string(), data['to'], mail_from, data['subject']) except SMTPException, e: self.status = str(e)
def _send_email(self, template, data): message = template(**data) sendmail(self, message)