当前位置: 首页>>代码示例>>Python>>正文


Python Mailer.send方法代码示例

本文整理汇总了Python中marrow.mailer.Mailer.send方法的典型用法代码示例。如果您正苦于以下问题:Python Mailer.send方法的具体用法?Python Mailer.send怎么用?Python Mailer.send使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在marrow.mailer.Mailer的用法示例。


在下文中一共展示了Mailer.send方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: send_mail_via_smtp_

# 需要导入模块: from marrow.mailer import Mailer [as 别名]
# 或者: from marrow.mailer.Mailer import send [as 别名]
    def send_mail_via_smtp_(config, payload):
        """
        Send email via SMTP
        :param config:
        :param payload:
        :return:
        """
        mailer_config = {
            'transport': {
                'use': 'smtp',
                'host': config['host'],
                'username': config['username'],
                'password': config['password'],
                'tls': config['encryption'],
                'port': config['port']
            }
        }

        mailer = Mailer(mailer_config)
        mailer.start()
        message = Message(author=payload['from'], to=payload['to'])
        message.subject = payload['subject']
        message.plain = strip_tags(payload['html'])
        message.rich = payload['html']
        mailer.send(message)
        mailer.stop()
开发者ID:PareshMayani,项目名称:open-event-android,代码行数:28,代码来源:notification.py

示例2: test_send

# 需要导入模块: from marrow.mailer import Mailer [as 别名]
# 或者: from marrow.mailer.Mailer import send [as 别名]
    def test_send(self):
        message = Bunch(id="foo")

        interface = Mailer(base_config)

        with pytest.raises(MailerNotRunning):
            interface.send(message)

        interface.start()

        # logging.getLogger().handlers[0].truncate()
        # messages = logging.getLogger().handlers[0].buffer

        assert interface.send(message) == (message, True)

        # assert messages[0] == "Attempting delivery of message foo."
        # assert messages[-1] == "Message foo delivered."

        message_fail = Bunch(id="bar", die=True)

        with pytest.raises(Exception):
            interface.send(message_fail)

            # assert messages[-4] == "Attempting delivery of message bar."
            # assert messages[-3] == "Acquired existing transport instance."
            # assert messages[-2] == "Shutting down transport due to unhandled exception."
            # assert messages[-1] == "Delivery of message bar failed."

        interface.stop()
开发者ID:nandoflorestan,项目名称:marrow.mailer,代码行数:31,代码来源:test_core.py

示例3: SendEmail

# 需要导入模块: from marrow.mailer import Mailer [as 别名]
# 或者: from marrow.mailer.Mailer import send [as 别名]
class SendEmail(object):
    def __init__(self, username="", password="", use="smtp", host="smtp.exmail.qq.com", port="25"):
        self.username = username
        self.mailer = Mailer(
            {
                "transport": {"use": use, "host": host, "port": port, "username": username, "password": password},
                "manager": {},
            }
        )

    def send_email(self, to, subject, content, author=""):
        self.mailer.start()
        self.mailer.send(Message(author=author or self.username, to=to, subject=subject, plain=content))
        self.mailer.stop()
开发者ID:Brightcells,项目名称:thingsforinternet,代码行数:16,代码来源:send_email.py

示例4: passwdreset

# 需要导入模块: from marrow.mailer import Mailer [as 别名]
# 或者: from marrow.mailer.Mailer import send [as 别名]
 def passwdreset(self):
     """Render password reset page"""
     c.came_from = '/'
     c.login_counter = 0
     c.form = ResetPwForm(request.POST, csrf_context=session)
     if request.method == 'POST' and c.form.validate():
         key_seed = '%s%s' % (c.form.email.data, arrow.utcnow().ctime())
         token = hashlib.sha1(key_seed).hexdigest()
         user = Session.query(User)\
                         .filter(User.email == c.form.email.data)\
                         .one()
         if not user.local:
             flash(_('The account %s is an external account, use your'
                     ' External systems to change the password. '
                     'Contact your system adminstrator if you do not '
                     'know which external systems you authenticate to')
                     % user.email)
             redirect(url('/accounts/login'))
         rtoken = Session\
                 .query(ResetToken.used)\
                 .filter(ResetToken.used == false())\
                 .filter(ResetToken.user_id == user.id)\
                 .all()
         if not rtoken:
             rtoken = ResetToken(token, user.id)
             Session.add(rtoken)
             Session.commit()
             host = URL_PREFIX_RE.sub('', request.host_url)
             c.username = user.username
             c.firstname = user.firstname or user.username
             c.reset_url = url('accounts-pw-token-reset',
                             token=token,
                             host=host)
             text = self.render('/email/pwreset.txt')
             mailer = Mailer(get_conf_options(config))
             mailer.start()
             sdrnme = config.get('baruwa.custom.name', 'Baruwa')
             email = Msg(author=[(sdrnme,
                         config.get('baruwa.reports.sender'))],
                         to=[('', c.form.email.data)],
                         subject=_("[%s] Password reset request") % sdrnme)
             email.plain = text
             mailer.send(email)
             mailer.stop()
         flash(_('An email has been sent to the address provided, '
                 'please follow the instructions in that email to '
                 'reset your password.'))
         redirect(url('/accounts/login'))
     return self.render('/accounts/login.html')
开发者ID:baruwaproject,项目名称:baruwa2,代码行数:51,代码来源:accounts.py

示例5: test_send

# 需要导入模块: from marrow.mailer import Mailer [as 别名]
# 或者: from marrow.mailer.Mailer import send [as 别名]
 def test_send(self):
     message = Bunch(id='foo')
     
     interface = Mailer(base_config)
     
     self.assertRaises(MailerNotRunning, interface.send, message)
     
     interface.start()
     
     logging.getLogger().handlers[0].truncate()
     messages = logging.getLogger().handlers[0].buffer
     
     self.assertEqual(interface.send(message), (message, True))
     
     self.assertEqual(messages[0].getMessage(), "Attempting delivery of message foo.")
     self.assertEqual(messages[-1].getMessage(), "Message foo delivered.")
     
     message_fail = Bunch(id='bar', die=True)
     self.assertRaises(Exception, interface.send, message_fail)
     
     self.assertEqual(messages[-4].getMessage(), "Attempting delivery of message bar.")
     self.assertEqual(messages[-3].getMessage(), "Acquired existing transport instance.")
     self.assertEqual(messages[-2].getMessage(), "Shutting down transport due to unhandled exception.")
     self.assertEqual(messages[-1].getMessage(), "Delivery of message bar failed.")
     
     interface.stop()
开发者ID:DatatracCorporation,项目名称:marrow.mailer,代码行数:28,代码来源:test_core.py

示例6: send_spam_alert

# 需要导入模块: from marrow.mailer import Mailer [as 别名]
# 或者: from marrow.mailer.Mailer import send [as 别名]
def send_spam_alert(number, calls_today, calls_per_minute, concurrent_calls):
    if not config.getboolean('email', 'enabled'):
        return

    mailer = Mailer({'transport.use': 'sendmail'})

    message = Message(author=config.get('mail', 'from'),
                      to=config.get('mail', 'to'))
    message.subject = config.get('mail', 'subject')
    message.plain = EMAIL_MESSAGE.format(number=number,
                                         calls_today=calls_today,
                                         calls_per_minute=calls_per_minute,
                                         concurrent_calls=concurrent_calls)

    mailer.start()
    mailer.send(message)
    mailer.stop()
开发者ID:gelendir,项目名称:becky,代码行数:19,代码来源:call_limit.py

示例7: MailingAdapter

# 需要导入模块: from marrow.mailer import Mailer [as 别名]
# 或者: from marrow.mailer.Mailer import send [as 别名]
class MailingAdapter(object):

    def __init__(self, host, port):
        self.mailer = Mailer(dict(
            manager = dict(
                use = 'immediate'),
            transport = dict(
                use = 'smtp',
                port = port,
                host = host)))
        self.mailer.start()

    def send_mail(self, to_address, from_address, body):
        message = Message(author=from_address, to=to_address)
        message.subject = "Testing Marrow Mailer"
        message.plain = body
        self.mailer.send(message)
开发者ID:philipcristiano,项目名称:transporter,代码行数:19,代码来源:mailing_adapter.py

示例8: command

# 需要导入模块: from marrow.mailer import Mailer [as 别名]
# 或者: from marrow.mailer.Mailer import send [as 别名]
    def command(self):
        "command"
        self.init()
        if self.options.email is None:
            print "\nA valid email is required\n"
            print self.parser.print_help()
            sys.exit(2)

        starttime = arrow.utcnow().datetime

        if self.options.report_period == 'daily':
            endtime = starttime - datetime.timedelta(days=1)
        elif self.options.report_period == 'weekly':
            endtime = starttime - datetime.timedelta(weeks=1)
        else:
            endtime = starttime - datetime.timedelta(weeks=4)

        params = dict(spamscore=self.options.spamscore, num=self.options.num,
                    starttime=starttime, endtime=endtime)

        sql = text("""SELECT clientip, COUNT(clientip) a
                    FROM messages WHERE sascore >= :spamscore
                    AND (timestamp BETWEEN :endtime AND :starttime)
                    GROUP BY clientip HAVING COUNT(clientip) >= :num
                    ORDER BY a DESC;""")
        results = Session.execute(sql, params=params)
        if results.rowcount:
            if self.options.include_count is False:
                records = [result.clientip for result in results]
            else:
                records = ["%s\t%d" % tuple(result) for result in results]
            content = "\n".join(records)
            if self.options.dry_run is True:
                print content
            else:
                mailer = Mailer(get_conf_options(self.conf))
                mailer.start()
                email = Msg(author=self.conf['baruwa.reports.sender'],
                            to=self.options.email, subject='TSL')
                email.plain = content
                try:
                    mailer.send(email)
                except (TransportFailedException, MessageFailedException), err:
                    print >> sys.stderr, err
                mailer.stop()
开发者ID:baruwaproject,项目名称:baruwa2,代码行数:47,代码来源:topspammers.py

示例9: Mailer

# 需要导入模块: from marrow.mailer import Mailer [as 别名]
# 或者: from marrow.mailer.Mailer import send [as 别名]
class Mailer(object):
    def __init__(self):
        self.config = Config().config['mail']
        self.mailer = MarrowMailer(
            dict(
                transport=dict(debug=True,
                               **self.config),
                manager=dict(),
                ),
            )

    def send(self, message):
        self.mailer.start()
        self.mailer.send(message)
        self.mailer.stop()
        pass

    def send_activation_message_to_mentor(self, mentor):
        message = ActivationMessage(mentor, Config().config['secret_key'])
        self.send(message)
开发者ID:ncgaskin,项目名称:mentor-finder,代码行数:22,代码来源:mailers.py

示例10: send_email

# 需要导入模块: from marrow.mailer import Mailer [as 别名]
# 或者: from marrow.mailer.Mailer import send [as 别名]
def send_email(to, subject, body):
    host = config.get('email', 'host')
    author = config.get('email', 'from')
    username = config.get('email', 'username')
    password = _get_email_password(username)

    mailer = Mailer({'manager': {'use': 'immediate'},
                     'transport': {'use': 'smtp',
                                   'host': host,
                                   'local_hostname': '[192.168.32.254]',
                                   'username': username,
                                   'password': password,
                                   'tls': 'optional'}
                     })

    message = Message(author=author, to=to, subject=subject, plain=body)

    puts("Sending email to {}".format(to))
    mailer.start()
    mailer.send(message)
    mailer.stop()
开发者ID:alafarcinade,项目名称:xivo-tools,代码行数:23,代码来源:email.py

示例11: send_mail

# 需要导入模块: from marrow.mailer import Mailer [as 别名]
# 或者: from marrow.mailer.Mailer import send [as 别名]
def send_mail(subject, plain, html):
  """This function assumes that email is HTML formatted"""
  mailer = Mailer(dict( transport = dict(
    use = 'smtp',
    debug = config.EMAIL_DEBUG,
    host = config.EMAIL_HOST,
    port = config.EMAIL_PORT,
    username = config.EMAIL_FROM,
    password = config.EMAIL_PASS,
    tls = config.EMAIL_SSL),
    manager = dict())
  )

  mailer.start()
  message = mailer.new()
  message.subject = subject
  message.author = config.EMAIL_FROM
  message.to = config.EMAIL_TO
  message.plain = plain
  message.rich = html
  mailer.send(message)
  mailer.stop()
开发者ID:sarlalian,项目名称:watchmen,代码行数:24,代码来源:mailer.py

示例12: pwtokenreset

# 需要导入模块: from marrow.mailer import Mailer [as 别名]
# 或者: from marrow.mailer.Mailer import send [as 别名]
 def pwtokenreset(self, token):
     """Reset password using token"""
     try:
         token = Session.query(ResetToken)\
                 .filter(ResetToken.token == token)\
                 .filter(ResetToken.used == false()).one()
         threshold = token.timestamp + timedelta(minutes=20)
         if arrow.utcnow().datetime > threshold:
             Session.delete(token)
             Session.commit()
             raise NoResultFound
         user = self._get_user(token.user_id)
         if not user or user.is_superadmin:
             raise NoResultFound
         passwd = mkpasswd()
         user.set_password(passwd)
         Session.add(user)
         Session.delete(token)
         Session.commit()
         c.passwd = passwd
         c.firstname = user.firstname or user.username
         text = self.render('/email/pwchanged.txt')
         mailer = Mailer(get_conf_options(config))
         mailer.start()
         sdrnme = config.get('baruwa.custom.name', 'Baruwa')
         email = Msg(author=[(sdrnme,
                     config.get('baruwa.reports.sender'))],
                     to=[('', user.email)],
                     subject=_("[%s] Password reset") % sdrnme)
         email.plain = text
         mailer.send(email)
         mailer.stop()
         flash(_('The password has been reset, check your email for'
                 ' the temporary password you should use to login.'))
     except NoResultFound:
         msg = _('The token used is invalid or does not exist')
         flash_alert(msg)
         log.info(msg)
     redirect(url('/accounts/login'))
开发者ID:baruwaproject,项目名称:baruwa2,代码行数:41,代码来源:accounts.py

示例13: SendEmail

# 需要导入模块: from marrow.mailer import Mailer [as 别名]
# 或者: from marrow.mailer.Mailer import send [as 别名]
class SendEmail(object):
    def __init__(self):
        self.mailer = Mailer(dict(
            transport=dict(
                use='smtp',
                host='smtp.gmail.com',
                port='587',
                username=username,
                password=password,
                tls='required',
                debug=False),
            manager=dict()))
        self.mailer.start()

    def send(self, to, html_body, plain_body):
        message = Message(author=from_email, to=to)
        message.subject = subject
        message.plain = plain_body
        message.rich = html_body
        self.mailer.send(message)

    def stop_sending(self):
        self.mailer.stop()

    def construct_html_email(self):
        user_list = get_users_to_send_data()
        data = get_data_to_send()

        #create html
        #f = open("templates/email.html", "r")
        #text = f.read()
        #t = Template(unicode(text, errors='ignore'))
        #text = t.substitute(links=result_map["html"] + "</ol>")
        #result_map["html"] = text

        for user in user_list:
            self.send(to=user["email"], html_body="%s" % data,
                      plain_body="data_plain")
开发者ID:roopeshvaddepally,项目名称:bayareahash,代码行数:40,代码来源:mail.py

示例14: send

# 需要导入模块: from marrow.mailer import Mailer [as 别名]
# 或者: from marrow.mailer.Mailer import send [as 别名]
def send(rst, html, email, name, cc):
    from marrow.mailer import Mailer, Message

    mailer = Mailer(
        dict(
            transport = dict(
                use = 'smtp',
                host = 'localhost')))

    mailer.start()

    message = Message(
        author="[email protected]",
        to=email,
        cc=cc,
        bcc='[email protected]'
    )

    message.subject = "Karatbars replicated website for {0}".format(name)
    message.rich = html
    message.plain = rst

    mailer.send(message)
    mailer.stop()
开发者ID:metaperl,项目名称:freegold-focus,代码行数:26,代码来源:email_rst.py

示例15: Mailer

# 需要导入模块: from marrow.mailer import Mailer [as 别名]
# 或者: from marrow.mailer.Mailer import send [as 别名]
import logging
from marrow.mailer import Message, Mailer
logging.basicConfig(level=logging.DEBUG)

mail = Mailer({
        'manager.use': 'futures',
        'transport.use': 'imap',
        'transport.host': '',
        'transport.ssl': True,
        'transport.username': '',
        'transport.password': '',
        'transport.folder': 'Marrow'
    })

mail.start()

message = Message([('Alice Bevan-McGregor', '[email protected]')], [('Alice Two', '[email protected]')], "This is a test message.", plain="Testing!")

mail.send(message)
mail.stop()
开发者ID:DatatracCorporation,项目名称:marrow.mailer,代码行数:22,代码来源:imap.py


注:本文中的marrow.mailer.Mailer.send方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。