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


Python EmailMessage.set_content方法代码示例

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


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

示例1: send_email

# 需要导入模块: from email.message import EmailMessage [as 别名]
# 或者: from email.message.EmailMessage import set_content [as 别名]
    def send_email(self, recipient_email, subject, body):
        """Sends an email to a defined address. """
        
        # prepare message
        msg = EmailMessage()
        msg['Subject'] = subject
        msg['From'] = Address(self.sender_email) #self.sender_name, addr_spec=
        msg['To'] = Address(self.sender_name, recipient_email)

        msg.set_content(body)

        '''
        message = MIMEText(body)
        message["Subject"] = subject 
        message["From"] = self.mail
        message["To"] = recipient_email
        msg = message.as_string()
        '''
        
        server = smtplib.SMTP(self.server)
        
        if self.use_tls: # deliberately starts tls if using TLS
            server.ehlo()
            server.starttls()
            server.ehlo()
            
        server.login(self.login, self.password) 
        server.send_message(msg)
        server.quit()
        return
开发者ID:lenarother,项目名称:pyhome,代码行数:32,代码来源:send_email.py

示例2: do_genmime

# 需要导入模块: from email.message import EmailMessage [as 别名]
# 或者: from email.message.EmailMessage import set_content [as 别名]
def do_genmime(args):
    """Execute the ``genmime`` subcommand. Unlike ``genhtml``, this command
    inlines images (which ``genhtml`` can't do becaus ``cid`` embedding is not,
    AFAIK, usable outside of email clients, but ``genhtml`` is most useful for
    previewing emails in browsers!)."""
    # Set up the email
    md_source = args.source.read()
    mail = EmailMessage()
    mail["From"] = Address(args.sender_name, args.sender_email)
    issue_no, _, _ = load_issue(md_source)
    mail["Subject"] = "Frontiers Fortnightly #{}".format(issue_no)

    # First, produce the text part
    text_content = render_mail_template(md_source, TEXT_TEMPLATE_NAME, args.sender_name, args.sender_email)
    mail.set_content(text_content)

    # Next, produce the HTML part
    minified_html = generate_html(md_source, HTML_TEMPLATE_NAME, args.sender_name, args.sender_email)
    inlined_html = inline_images(minified_html)
    mail.add_alternative(inlined_html, subtype="html")

    if "b" in args.dest.mode:
        args.dest.write(bytes(mail))
    else:
        args.dest.write(str(mail))
开发者ID:anu-maker-club,项目名称:newsletter,代码行数:27,代码来源:render.py

示例3: _send

# 需要导入模块: from email.message import EmailMessage [as 别名]
# 或者: from email.message.EmailMessage import set_content [as 别名]
    def _send(self, msg_content):
        # reference
        # - https://docs.python.org/3/library/email-examples.html
        send_msg = EmailMessage()
        send_msg['From'] = self.email_from

        # multiple mail_to
        #  ex) [email protected],[email protected]
        send_msg['To'] = self.email_to

        if len(self.email_cc) > 0:
            send_msg['CC'] = self.email_cc

        send_msg['Subject'] = self.subject
        send_msg.set_content(msg_content)

        s = smtplib.SMTP(self.smtp_server, self.smtp_port)

        # Hostname to send for this command defaults
        #  to the fully qualified domain name of the local host.
        s.ehlo()

        # Puts connection to SMTP server in TLS mode
        s.starttls()
        s.ehlo()

        s.login(self.smtp_account, self.smtp_password)
        s.set_debuglevel(1)

        s.send_message(send_msg)
        s.quit()
开发者ID:morenice,项目名称:excellent,代码行数:33,代码来源:email_sender.py

示例4: make_message_object

# 需要导入模块: from email.message import EmailMessage [as 别名]
# 或者: from email.message.EmailMessage import set_content [as 别名]
def make_message_object(origin, destination, subject, content):
    m = EmailMessage()
    m.set_content(content)
    m['Subject'] = subject
    m['From'] = origin
    m['To'] = destination
    return m
开发者ID:PhilippeCarphin,项目名称:tests,代码行数:9,代码来源:test_email.py

示例5: sendEmail

# 需要导入模块: from email.message import EmailMessage [as 别名]
# 或者: from email.message.EmailMessage import set_content [as 别名]
def sendEmail(args, returnCode):
    """
    Try to send an email to the user. Errors must be non-fatal.
    """
    try:
        import smtplib
        from email.message import EmailMessage
        msg = EmailMessage()
        msg['Subject'] = "Snakepipes completed"
        msg['From'] = args.emailSender
        msg['To'] = args.emailAddress
        if returnCode == 0:
            msg.set_content("The pipeline finished successfully\n")
        else:
            msg.set_content("The pipeline failed with exit code {}\n".format(returnCode))

        if args.onlySSL:
            s = smtplib.SMTP_SSL(args.smtpServer, port=args.smtpPort)
        else:
            s = smtplib.SMTP(args.smtpServer, port=args.smtpPort)
        if args.smtpUsername:
            s.login(args.smtpUsername, args.smtpPassword)
        s.send_message(msg)
        s.quit()
    except:
        sys.stderr.write("An error occured while sending the email.\n")
        pass
开发者ID:kilpert,项目名称:snakemake_workflows,代码行数:29,代码来源:common_functions.py

示例6: flush

# 需要导入模块: from email.message import EmailMessage [as 别名]
# 或者: from email.message.EmailMessage import set_content [as 别名]
    def flush(self):
        self.acquire()
        try:
            if len(self.buffer) > 0:
                import smtplib
                from email.message import EmailMessage
                import email.utils

                port = self.mailport
                if not port:
                    port = smtplib.SMTP_PORT
                smtp = smtplib.SMTP(
                    self.mailhost, port, timeout=self.smtp_timeout)
                msg = EmailMessage()
                msg['From'] = self.fromaddr
                msg['To'] = ','.join(self.toaddrs)
                msg['Subject'] = self.getSubject(self.buffer)
                msg['Date'] = email.utils.localtime()
                msg.set_content('\n'.join(self.format(r) for r in self.buffer))
                if self.username:
                    if self.secure is not None:
                        smtp.ehlo()
                        smtp.starttls(*self.secure)
                        smtp.ehlo()
                    smtp.login(self.username, self.password)
                smtp.send_message(msg)
                smtp.quit()
                self.buffer = []
        except Exception:
            self.handleError(self.buffer[-1])
        finally:
            self.release()
开发者ID:dougalsutherland,项目名称:PreviouslyTV-helper,代码行数:34,代码来源:deploy_base.py

示例7: test_send_message_uses_smtputf8_if_addrs_non_ascii

# 需要导入模块: from email.message import EmailMessage [as 别名]
# 或者: from email.message.EmailMessage import set_content [as 别名]
    def test_send_message_uses_smtputf8_if_addrs_non_ascii(self):
        msg = EmailMessage()
        msg['From'] = "Páolo <fő[email protected]>"
        msg['To'] = 'Dinsdale'
        msg['Subject'] = 'Nudge nudge, wink, wink \u1F609'
        # XXX I don't know why I need two \n's here, but this is an existing
        # bug (if it is one) and not a problem with the new functionality.
        msg.set_content("oh là là, know what I mean, know what I mean?\n\n")
        # XXX smtpd converts received /r/n to /n, so we can't easily test that
        # we are successfully sending /r/n :(.
        expected = textwrap.dedent("""\
            From: Páolo <fő[email protected]>
            To: Dinsdale
            Subject: Nudge nudge, wink, wink \u1F609
            Content-Type: text/plain; charset="utf-8"
            Content-Transfer-Encoding: 8bit
            MIME-Version: 1.0

            oh là là, know what I mean, know what I mean?
            """)
        smtp = smtplib.SMTP(
            HOST, self.port, local_hostname='localhost', timeout=3)
        self.addCleanup(smtp.close)
        self.assertEqual(smtp.send_message(msg), {})
        self.assertEqual(self.serv.last_mailfrom, 'fő[email protected]')
        self.assertEqual(self.serv.last_rcpttos, ['Dinsdale'])
        self.assertEqual(self.serv.last_message.decode(), expected)
        self.assertIn('BODY=8BITMIME', self.serv.last_mail_options)
        self.assertIn('SMTPUTF8', self.serv.last_mail_options)
        self.assertEqual(self.serv.last_rcpt_options, [])
开发者ID:CCNITSilchar,项目名称:cpython,代码行数:32,代码来源:test_smtplib.py

示例8: flush

# 需要导入模块: from email.message import EmailMessage [as 别名]
# 或者: from email.message.EmailMessage import set_content [as 别名]
 def flush(self):
      # Add extra newline to info() messages for separation in logfile
      if not self.buffer:
           _logger.info("No warnings, no email to send\n")
           return
      _logger.info(f"Sending logging email with {len(self.buffer)} records\n")
      txt = ''.join(self.format(record)+'\n' for record in self.buffer)
      msg = EmailMessage()
      msg['Subject'] = "mfaliquot: {}.py has something to say".format(self.scriptname)
      msg['To'] = ', '.join(self.to_addrs)
      msg['From'] = self.from_addr
      msg.set_content("Something went wrong (?) while {}.py was running:\n\n".format(self.scriptname)+txt)
      try:
           s = SMTP()
           s.connect(self.host, self.port)
           s.starttls()
           if self.username and self.password:
                s.login(self.username, self.password)
           s.send_message(msg)
           s.quit()
      except SMTPException as e:
           _logger.exception("Logging email failed to send:", exc_info=e, extra=self._special_kwarg)
      except OSError as e:
           _logger.exception("Some sort of smtp problem:", exc_info=e, extra=self._special_kwarg)
      except BaseException as e:
           _logger.exception("Unknown error while attempting to email:", exc_info=e, extra=self._special_kwarg)
      else:
           self.buffer.clear()
开发者ID:dubslow,项目名称:MersenneForumAliquot,代码行数:30,代码来源:__init__.py

示例9: create_msg

# 需要导入模块: from email.message import EmailMessage [as 别名]
# 或者: from email.message.EmailMessage import set_content [as 别名]
def create_msg(recv: str, subject: str, body: str, sender: str=SENDER_EMAIL) -> EmailMessage:
    msg = EmailMessage()
    msg['To'] = recv
    msg['From'] = sender
    msg['Subject'] = subject
    msg.set_content(body)

    return msg
开发者ID:thismachinechills,项目名称:cheapbook,代码行数:10,代码来源:send.py

示例10: sample_message

# 需要导入模块: from email.message import EmailMessage [as 别名]
# 或者: from email.message.EmailMessage import set_content [as 别名]
def sample_message():
    msg = EmailMessage()
    msg['From'] = '[email protected]'
    msg['To'] = 'Test Recipient <[email protected]>, [email protected]'
    msg['Cc'] = 'Test CC <[email protected]>, [email protected]'
    msg['Bcc'] = 'Test BCC <[email protected]>, [email protected]'
    msg.set_content('Test content')
    return msg
开发者ID:asphalt-framework,项目名称:asphalt-mailer,代码行数:10,代码来源:conftest.py

示例11: send_email

# 需要导入模块: from email.message import EmailMessage [as 别名]
# 或者: from email.message.EmailMessage import set_content [as 别名]
def send_email(email, subject, message):
    msg = EmailMessage()
    msg['Subject'] = subject
    msg['From'] = '[email protected]'
    msg['To'] = email
    msg.set_content(message)

    with smtplib.SMTP('localhost') as s:
        s.send_message(msg)
开发者ID:Braedon,项目名称:up,代码行数:11,代码来源:up.py

示例12: __create_message

# 需要导入模块: from email.message import EmailMessage [as 别名]
# 或者: from email.message.EmailMessage import set_content [as 别名]
def __create_message(subject, message_body, from_email, to_emails):
    '''
    Take the subject, message body, from email, and to emails list and create
    a message object to send off.
    '''
    msg = EmailMessage()
    msg.set_content(message_body)
    msg['Subject'] = subject
    msg['From'] = from_email
    msg['To'] = __get_list(to_emails)
    return msg
开发者ID:DevMattM,项目名称:qipr_approver,代码行数:13,代码来源:send_email.py

示例13: post

# 需要导入模块: from email.message import EmailMessage [as 别名]
# 或者: from email.message.EmailMessage import set_content [as 别名]
    def post(self):
        msg = EmailMessage()
        msg['Subject'] = self.get_argument('subject')
        msg['To']      = self.get_argument('email')
        msg['From']    = FROM_ADDR
        msg.set_content(self.get_argument('message'))
        
        smtp = yield self.application.get_smtp_client()
        smtp.send_message(msg)

        self.render('index.html')
开发者ID:ricardoyorky,项目名称:tornado-smtp,代码行数:13,代码来源:test.py

示例14: create_preference_message

# 需要导入模块: from email.message import EmailMessage [as 别名]
# 或者: from email.message.EmailMessage import set_content [as 别名]
def create_preference_message() -> PreferenceEmail:
    """Creates new email with a swa preferences from a template

    :return: PreferenceEmail
    """
    msg = EmailMessage()
    msg['X-Oddpost-Class'] = 'prefs'
    msg['Subject'] = '[prefs(v2.1) data]'
    msg['From'] = '[email protected]'
    msg.set_charset('utf-8')
    msg.set_content(PREFERENCE_TEMPLATE)
    return PreferenceEmail(0, msg)
开发者ID:scalix,项目名称:general-utilities,代码行数:14,代码来源:change_swa_preferences.py

示例15: _prepare_message

# 需要导入模块: from email.message import EmailMessage [as 别名]
# 或者: from email.message.EmailMessage import set_content [as 别名]
	def _prepare_message(self):
		msgs = []
		for rec_group in self.recipients:
			msg = EmailMessage()
			msg['From'] = self.frm
			msg['To'] = rec_group
			content = self.content
			msg['Subject'] = content['meta']['subject'][0]
			msg.set_content(content['raw'])
			msg.add_alternative(content['html'], subtype='html')
			msgs.append(msg)
		return msgs
开发者ID:pirati-cz,项目名称:byro,代码行数:14,代码来源:mail.py


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