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


Python SMTP.noop方法代码示例

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


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

示例1: test_email

# 需要导入模块: from smtplib import SMTP [as 别名]
# 或者: from smtplib.SMTP import noop [as 别名]
def test_email(email_config):

    subject = "Héèéè"
    message_content = "Contentééééééé\r\nhûhûhhû\r\n"
    msg = MIMEText(message_content.encode('utf-8'), 'plain', 'utf-8')
    msg['Subject'] = Header(subject, 'utf-8')
    msg['From'] = email_config["from_address"]
    msg['To'] = email_config["to_test_address"]


    smtp = SMTP(email_config["smtp_server"])
    try:
        smtp.set_debuglevel(True)
        print("\rdbg smtp.noop()")
        print(smtp.noop())

        print("\rdbg smtp.starttls()")
        print(smtp.starttls())

        print("\rdbg smtp.login()")
        print(smtp.login(email_config["from_username"], email_config["from_password"]))

        print("\rdbg smtp.send_message()")
        print(smtp.send_message(msg))
    except Exception as inst:
        print(inst)

    print("\rdbg smtp.quit()")
    print(smtp.quit())
开发者ID:vaillancourt,项目名称:christmas,代码行数:31,代码来源:pick.py

示例2: send_a_mail

# 需要导入模块: from smtplib import SMTP [as 别名]
# 或者: from smtplib.SMTP import noop [as 别名]
def send_a_mail(email_config, dest_name, dest_adress, picked_name, dry_run):
    subject = "La Pige de Noël"
    message_content = dest_name + "!\r\nLa personne que tu as pigée pour l'échange de cadeau de Noël est : \r\n" + picked_name
    msg = MIMEText(message_content.encode('utf-8'), 'plain', 'utf-8')
    msg['Subject'] = Header(subject, 'utf-8')
    msg['From'] = email_config["from_address"]
    msg['To'] = dest_adress

    if dry_run:
        print(msg.as_string())
        return

    smtp = SMTP(email_config["smtp_server"])
    try:
        smtp.set_debuglevel(True)
        smtp.noop()
        smtp.starttls()
        smtp.login(email_config["from_username"], email_config["from_password"])
        smtp.send_message(msg)

    except Exception as inst:
        print(inst)

    smtp.quit()
开发者ID:vaillancourt,项目名称:christmas,代码行数:26,代码来源:pick.py

示例3: SMTP

# 需要导入模块: from smtplib import SMTP [as 别名]
# 或者: from smtplib.SMTP import noop [as 别名]
class SMTP(object):
    """ Class to handle smtp connection and email sending """

    def __init__(self, username, password, host, mail_from, mail_to):
        self.mail_from = mail_from
        self.mail_to = mail_to

        self.username = username
        self.password = password
        self.host = host

        self.login()
        atexit.register(self.quit)

    def login(self):
        self.server = SMTPLib(self.host)
        self.server.login(self.username, self.password)

    def quit(self):
        if self.server.noop()[0] == 250:
            self.server.quit()

    def format_msg(self, title, desc, images=None, mail_to=None):
        """ create a MIMEMultipart with this title, desc, and images """
        msg = MIMEMultipart()
        msg['Subject'] = title
        msg['From'] = self.mail_from
        msg['To'] = mail_to or self.mail_to

        if images:
            for image in images:
                if os.path.exists(image):
                    msg.attach(MIMEImage(file(image).read()))
        msg.attach(MIMEText(desc))

        return msg.as_string()

    @relog
    def send_mail(self, title, desc, images=None, mail_to=None):
        """ send the given MIMEMultipart """
        msg = self.format_msg(title, desc, images, mail_to)
        self.server.sendmail(self.mail_from, mail_to or self.mail_to, msg)
开发者ID:sayoun,项目名称:alarm_console,代码行数:44,代码来源:smtp.py

示例4: Session

# 需要导入模块: from smtplib import SMTP [as 别名]
# 或者: from smtplib.SMTP import noop [as 别名]
class Session(object):
    """
    Represents a connection to some server or external
    service, e.g. some REST API. The underlying transport
    defaults to SMTP but can be subclassed.

    :param **kwargs: Keyword arguments to be passed to
        the underlying transport.
    """

    def __init__(self, **kwargs):
        self.conn = SMTP(**kwargs)
        self.conn.ehlo()

    def teardown(self):
        """
        Tear down the connection.
        """
        self.conn.quit()

    def send(self, envelope):
        """
        Send an *envelope* which may be an envelope
        or an enclosure-like object, see
        :class:`~mailthon.enclosure.Enclosure` and
        :class:`~mailthon.envelope.Envelope`, and
        returns a :class:`~mailthon.response.SendmailResponse`
        object.
        """
        rejected = self.conn.sendmail(
            stringify_address(envelope.sender),
            [stringify_address(k) for k in envelope.receivers],
            envelope.string(),
        )
        status_code, reason = self.conn.noop()
        return SendmailResponse(
            status_code,
            reason,
            rejected,
        )
开发者ID:eugene-eeo,项目名称:mailthon,代码行数:42,代码来源:postman.py

示例5: GoodGrammarTests

# 需要导入模块: from smtplib import SMTP [as 别名]
# 或者: from smtplib.SMTP import noop [as 别名]
class GoodGrammarTests(unittest.TestCase):
    """Collection of tests of valid SMTP grammar (i.e. they should not generate any error responses from server)"""
    
    addrs = [
        '[email protected]', '[email protected]', '[email protected]',
        '[email protected]', '[email protected]'
        ]

    def setUp(self):
        self.smtp = SMTP('localhost', 1025)

    def tearDown(self):
        # self.smtp.quit()
        self.smtp.close()
        self.smtp = None

    def assertOk(self, result):
      self.assertEqual(result, (250, 'Ok'))

    def testConnect(self):
        """On connecting the server sends a 220 response with a welcome message."""
        smtp = SMTP();
        self.assertEqual(smtp.connect('localhost', 1025), (220, 'test node.js smtpevent server 0.0.2'))
        smtp.quit();
        smtp.close()
        
    def testHelo(self):
        """The server responds to a valid HELO command."""
        self.assertEqual(self.smtp.helo('example.com'), (250, 'test Hello 127.0.0.1'))

    def testNoop(self):
        """The NOOP command takes no arguments."""
        self.assertOk(self.smtp.noop())
        
    def testQuit(self):
        """The QUIT command works without an argument"""
        self.assertEqual(self.smtp.quit(), (221, 'test closing connection'))

    def testQuitWithArgument(self):
        """The QUIT command works with an argument"""
        self.assertEqual(self.smtp.docmd('QUIT', 'See you later'), (221, 'test closing connection'))
        
    def testRset(self):
        """The RSET command takes no arguments."""
        self.assertOk(self.smtp.rset())
        
    def testMailFrom(self):
        """The MAIL command will extract the email address from the FROM:."""
        self.assertEqual(self.smtp.mail('[email protected]'), (250, 'Ok'))
        
    def testMailFromEmpty(self):
        """The MAIL command handles empty addresses"""
        self.assertEqual(self.smtp.mail('<>'), (250, 'Ok'))
    
    def testMultipleRcpts(self):
        """Multiple RCPT commands can be issued to add recipients."""
        self.assertOk(self.smtp.docmd('MAIL', 'FROM:<[email protected]>'))
        for rcpt in self.addrs:
            self.assertOk(self.smtp.docmd('RCPT', 'TO:<%s>' % rcpt))
    
    def testDataResponse(self):
        """The DATA instructs the self.smtp to end the message with <CR><LF>.<CR><LF>."""
        self.assertOk(self.smtp.mail('[email protected]'))
        self.assertOk(self.smtp.rcpt('[email protected]'))
        self.assertEqual(self.smtp.docmd('DATA'), (354, 'End data with <CR><LF>.<CR><LF>'))
开发者ID:femto113,项目名称:node-smtpevent,代码行数:67,代码来源:grammar.py


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