def send( message, to, from_email, from_name, subject=None, type='plain', charset=None, ): if service.app.config[name].get('to_email_override'): log.warning( 'Replacing the email %s with %s', to, service.app.config[name].get('to_email_override'), ) to = service.app.config[name].get('to_email_override') if to and isinstance(to, list) and isinstance(to[0], dict): to = ['%s <%s>'%(x.name, x.email) for x in to] subject = subject or service.app.config[name]['subject'] message = prepare( plain(message, type=type, charset=charset), from_name = from_name, from_email = from_email, to=to, subject=subject, ) debug_folder = service.app.config[name].get('debug_folder') if debug_folder: log.warning( 'Writing message to the debug folder, not sending ' 'it directly' ) fp = open( os.path.join( debug_folder, '%s - %s.txt'%(subject, to) ), 'wb' ) fp.write(str(message)) fp.close() else: sendmail = service.app.config[name].get('sendmail') if sendmail: return send_sendmail( message, sendmail, ) smtp_args = service.app.config[name]['smtp'] return send_smtp(message, **str_dict(smtp_args))
def _send_entry(entry): spacer = 78 * u'-' joiner = u'\n%s\n' % spacer content = joiner.join([ unescape(c.value) for c in entry.content ] ) content += joiner content += entry['link'] content = content.encode('utf-8') title = u'[%s] %s' % (entry.updated , entry.title) title = title.encode('utf-8') message = mail.plain(content, from_name = "Gumtree Monitor", from_email = "*****@*****.**", subject = title, to = emails) mail.send_smtp(message, 'localhost')
def send( message, to, from_email, from_name, subject=None, type='plain', charset=None, ): if service.app.config[name].get('to_email_override'): log.warning( 'Replacing the email %s with %s', to, service.app.config[name].get('to_email_override'), ) to = service.app.config[name].get('to_email_override') if to and isinstance(to, list) and isinstance(to[0], dict): to = ['%s <%s>' % (x.name, x.email) for x in to] subject = subject or service.app.config[name]['subject'] message = prepare( plain(message, type=type, charset=charset), from_name=from_name, from_email=from_email, to=to, subject=subject, ) debug_folder = service.app.config[name].get('debug_folder') if debug_folder: log.warning('Writing message to the debug folder, not sending ' 'it directly') fp = open( os.path.join(debug_folder, '%s - %s.txt' % (subject, to)), 'wb') fp.write(str(message)) fp.close() else: sendmail = service.app.config[name].get('sendmail') if sendmail: return send_sendmail( message, sendmail, ) smtp_args = service.app.config[name]['smtp'] return send_smtp(message, **str_dict(smtp_args))