本文整理汇总了Python中pyramid_mailer.mailer.Mailer类的典型用法代码示例。如果您正苦于以下问题:Python Mailer类的具体用法?Python Mailer怎么用?Python Mailer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Mailer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ThreadMailer
class ThreadMailer(threading.Thread):
"""
인덱스 추가/삭제를 위한 쓰레드
"""
def __init__(self):
threading.Thread.__init__(self)
self.queue = Queue.Queue()
self.mailer = Mailer(host="localhost")
def send(self, msg):
self.queue.put(msg)
def run(self):
while True:
# 큐에서 작업을 하나 가져온다
msg = self.queue.get()
self.mailer.send(msg)
log.info(msg.subject)
transaction.commit()
log.info("MAIL COMMITTED!")
# 작업 완료를 알리기 위해 큐에 시그널을 보낸다.
self.queue.task_done()
def end(self):
self.queue.join()
示例2: email
def email(subject=None, recipients=None, body=None):
mailer = Mailer(host='192.168.101.5')
message = Message(subject=subject,
sender='[email protected]',
recipients=recipients,
html=body)
mailer.send_immediately(message)
示例3: test_send_immediately_and_fail_silently
def test_send_immediately_and_fail_silently(self):
from pyramid_mailer.mailer import Mailer
from pyramid_mailer.message import Message
mailer = Mailer()
msg = Message(subject="testing", sender="[email protected]", recipients=["[email protected]"], body="test")
mailer.send_immediately(msg, True)
示例4: test_send
def test_send(self):
from pyramid_mailer.mailer import Mailer
from pyramid_mailer.message import Message
mailer = Mailer()
msg = Message(subject="testing", sender="[email protected]", recipients=["[email protected]"], body="test")
mailer.send(msg)
示例5: test_send_immediately_and_fail_silently
def test_send_immediately_and_fail_silently(self):
from pyramid_mailer.mailer import Mailer
from pyramid_mailer.message import Message
mailer = Mailer(host="localhost", port="28322")
msg = Message(subject="testing", sender="[email protected]", recipients=["[email protected]"], body="test")
result = mailer.send_immediately(msg, True)
self.assertEqual(result, None)
示例6: test_bcc_without_recipients
def test_bcc_without_recipients(self):
from pyramid_mailer.message import Message
from pyramid_mailer.mailer import Mailer
msg = Message(subject="testing", sender="[email protected]", body="testing", bcc=["[email protected]"])
mailer = Mailer()
msgid = mailer.send(msg)
response = msg.to_message()
self.assertFalse("Bcc: [email protected]" in text_type(response))
self.assertTrue(msgid)
示例7: test_send_without_body
def test_send_without_body(self):
from pyramid_mailer.message import Message
from pyramid_mailer.mailer import Mailer
from pyramid_mailer.exceptions import InvalidMessage
msg = Message(subject="testing", sender="[email protected]", recipients=["[email protected]"])
mailer = Mailer()
self.assertRaises(InvalidMessage, mailer.send, msg)
msg.html = "<b>test</b>"
mailer.send(msg)
示例8: main
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application. """
config = Configurator(settings=settings)
#set up beaker session
session_factory = session_factory_from_settings(settings)
config.set_session_factory(session_factory)
# add security tweens
# config.add_tween('aws_demo.tweens.clickjacking.clickjacking_factory')
# config.add_tween('aws_demo.tweens.secure_headers.secure_headers_factory')
config.registry['mailer'] = Mailer.from_settings(settings=settings)
# modify the built in json renderer to serialize dates properly
json_date_renderer = JSON()
json_date_renderer.add_adapter(datetime.datetime, new_datetime_adapter)
# set .html renderer to allow mako templating
config.add_renderer('.html', 'pyramid.mako_templating.renderer_factory')
config.add_renderer('.htm', 'pyramid.mako_templating.renderer_factory')
config.add_renderer('json', json_date_renderer)
config.add_static_view('static', 'static', cache_max_age=3600)
# login / registration
config.add_route('index_view', '/')
config.scan()
return config.make_wsgi_app()
示例9: main
def main(argv=sys.argv):
if len(argv) != 2:
usage(argv)
config_uri = argv[1]
setup_logging(config_uri)
settings = get_appsettings(config_uri)
engine = engine_from_config(settings, "sqlalchemy.")
mailer = Mailer.from_settings(settings)
DBSession.configure(bind=engine)
rootFolder = settings["reports.folder"]
request = Request.blank("/", base_url=settings["reports.app.url"])
env = bootstrap(config_uri, request=request)
request = env["request"]
try:
remove_groups(request)
remove_reports(request)
handleRootFolder(request, rootFolder)
# email_users(request, mailer)
email_admin_users(request, mailer)
transaction.commit()
except Exception as e:
transaction.abort()
stack = traceback.format_exc()
body = "Got an exception while processing reports: %s\n\n%s" % (e, stack)
message = Message(
subject="Famoso Reports - failed to process",
sender="[email protected]",
recipients=["[email protected]"],
body=body,
)
mailer.send_immediately(message)
示例10: main
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
engine = engine_from_config(settings, "sqlalchemy.")
DBSession.configure(bind=engine)
Base.metadata.bind = engine
authn_policy = AuthTktAuthenticationPolicy("sosecret", callback=groupfinder, hashalg="sha512")
authz_policy = ACLAuthorizationPolicy()
config = Configurator(settings=settings, root_factory="webapp.models.RootFactory")
config.set_authentication_policy(authn_policy)
config.set_authorization_policy(authz_policy)
config.registry["mailer"] = Mailer.from_settings(settings)
config.add_static_view("static", "static", cache_max_age=3600)
config.add_route("index", "/")
config.add_route("login", "/login")
config.add_route("logout", "/logout")
config.add_route("registration", "/registration")
# config.add_route('end_reg', '/activate/{a_code}')
config.add_route("verify", "/verify/{code}")
# config.add_route('confirm', '/confirm')
config.add_route("content", "/content/{id}")
config.add_route("about", "/about")
config.add_route("pay", "/pay")
config.add_route("preview", "/preview")
config.add_route("bundle_preview", "/bundle_preview")
config.add_route("b_content", "/bonus/{id}")
config.add_route("bundle", "/bundle/{id}")
config.add_route("account", "/account/{parameters}")
config.scan()
return config.make_wsgi_app()
示例11: main
def main(global_config, **settings):
"""
This function returns a Pyramid WSGI application.
"""
# the database session:
engine = engine_from_config(settings, 'sqlalchemy.')
DBSession.configure(bind=engine)
Base.metadata.bind = engine
# session_factory = session_factory_from_settings(settings)
config = Configurator(
settings=settings,
root_factory=get_root,
authentication_policy=GyAuthenticationPolicy(),
authorization_policy=GyAuthorizationPolicy(),
session_factory = session_factory_from_settings(settings),
request_factory = GyRequest,
)
config.add_static_view('static', 'static', cache_max_age=3600)
# config.include('pyramid_mailer')
mailer = Mailer.from_settings(settings)
config.registry['mailer'] = mailer
config.include('gy.core')
config.include('gy.blog')
config.add_notfound_view(gy_not_found, append_slash=True)
config.scan()
return config.make_wsgi_app()
示例12: mailer_factory_from_settings
def mailer_factory_from_settings(settings, prefix='mail.'):
"""
Factory function to create a Mailer instance from settings.
Equivalent to **Mailer.from_settings**
:versionadded: 0.2.2
"""
return Mailer.from_settings(settings, prefix)
示例13: test_send
def test_send(self):
from pyramid_mailer.mailer import Mailer
from pyramid_mailer.message import Attachment
from pyramid_mailer.message import Message
mailer = Mailer()
msg = Message(subject="testing",
sender="[email protected]",
recipients=["[email protected]"],
body="test")
msg.attach(Attachment('test.txt',
data=b"this is a test",
content_type="text/plain"))
mailer.send(msg)
示例14: mailer_factory_from_settings
def mailer_factory_from_settings(settings, prefix='mail.'):
"""
Factory function to create a Mailer instance from settings.
Equivalent to :meth:`pyramid_mailer.mailer.Mailer.from_settings`.
:versionadded: 0.2.2
"""
return Mailer.from_settings(settings, prefix)
示例15: main
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
authentication_policy = AuthTktAuthenticationPolicy('seekrit', callback=groupfinder)
authorization_policy = ACLAuthorizationPolicy()
engine = engine_from_config(settings, prefix='sqlalchemy.')
db_maker = sessionmaker(bind=engine)
settings['rel_db.sessionmaker'] = db_maker
config = Configurator(settings=settings,
root_factory='scielobooks.resources.RootFactory',
authentication_policy=authentication_policy,
authorization_policy=authorization_policy,
request_factory=MyRequest,
renderer_globals_factory=renderer_globals_factory)
config.include(pyramid_zcml)
config.load_zcml('configure.zcml')
config.include('pyramid_mailer')
config.include('pyramid_celery')
config.registry['mailer'] = Mailer.from_settings(settings)
config.registry['app_version'] = APP_VERSION
db_uri = settings['db_uri']
conn = couchdbkit.Server(db_uri)
config.registry.settings['db_conn'] = conn
config.add_subscriber(add_couch_db, NewRequest)
config.scan('scielobooks.models')
initialize_sql(engine)
if settings['serve_static_files'] == 'true':
config.add_static_view(name='static', path='static')
config.add_static_view('deform_static', 'deform:static')
config.add_static_view('/'.join((settings['db_uri'], settings['db_name'])), 'scielobooks:database')
config.add_static_view(settings['fileserver_url'], 'scielobooks:fileserver')
config.add_view(custom_forbidden_view, context=Forbidden)
config.add_translation_dirs('scielobooks:locale/')
config.set_locale_negotiator(custom_locale_negotiator)
my_session_factory = UnencryptedCookieSessionFactoryConfig('itsaseekreet')
config.set_session_factory(my_session_factory)
application = config.make_wsgi_app()
try:
if settings.get('newrelic.enable', 'False').lower() == 'true':
newrelic.agent.initialize(os.path.join(APP_PATH, '..', 'newrelic.ini'), settings['newrelic.environment'])
return newrelic.agent.wsgi_application()(application)
else:
return application
except IOError:
config.registry.settings['newrelic.enable'] = False
return application