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


Python EmailMessage.preamble方法代码示例

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


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

示例1: main

# 需要导入模块: from email.message import EmailMessage [as 别名]
# 或者: from email.message.EmailMessage import preamble [as 别名]
def main():
    parser = ArgumentParser(description="""\
Send the contents of a directory as a MIME message.
Unless the -o option is given, the email is sent by forwarding to your local
SMTP server, which then does the normal delivery process.  Your local machine
must be running an SMTP server.
""")
    parser.add_argument('-d', '--directory',
                        help="""Mail the contents of the specified directory,
                        otherwise use the current directory.  Only the regular
                        files in the directory are sent, and we don't recurse to
                        subdirectories.""")
    parser.add_argument('-o', '--output',
                        metavar='FILE',
                        help="""Print the composed message to FILE instead of
                        sending the message to the SMTP server.""")
    parser.add_argument('-s', '--sender', required=True,
                        help='The value of the From: header (required)')
    parser.add_argument('-r', '--recipient', required=True,
                        action='append', metavar='RECIPIENT',
                        default=[], dest='recipients',
                        help='A To: header value (at least one required)')
    args = parser.parse_args()
    directory = args.directory
    if not directory:
        directory = '.'
    # Create the message
    msg = EmailMessage()
    msg['Subject'] = 'Contents of directory %s' % os.path.abspath(directory)
    msg['To'] = ', '.join(args.recipients)
    msg['From'] = args.sender
    msg.preamble = 'You will not see this in a MIME-aware mail reader.\n'

    for filename in os.listdir(directory):
        path = os.path.join(directory, filename)
        if not os.path.isfile(path):
            continue
        # Guess the content type based on the file's extension.  Encoding
        # will be ignored, although we should check for simple things like
        # gzip'd or compressed files.
        ctype, encoding = mimetypes.guess_type(path)
        if ctype is None or encoding is not None:
            # No guess could be made, or the file is encoded (compressed), so
            # use a generic bag-of-bits type.
            ctype = 'application/octet-stream'
        maintype, subtype = ctype.split('/', 1)
        with open(path, 'rb') as fp:
            msg.add_attachment(fp.read(),
                               maintype=maintype,
                               subtype=subtype,
                               filename=filename)
    # Now send or store the message
    if args.output:
        with open(args.output, 'wb') as fp:
            fp.write(msg.as_bytes(policy=SMTP))
    else:
        with smtplib.SMTP('localhost') as s:
            s.send_message(msg)
开发者ID:1st1,项目名称:cpython,代码行数:60,代码来源:email-dir.py

示例2: EmailMessage

# 需要导入模块: from email.message import EmailMessage [as 别名]
# 或者: from email.message.EmailMessage import preamble [as 别名]
# Import smtplib for the actual sending function
import smtplib

# And imghdr to find the types of our images
import imghdr

# Here are the email package modules we'll need
from email.message import EmailMessage

# Create the container email message.
msg = EmailMessage()
msg['Subject'] = 'Our family reunion'
# me == the sender's email address
# family = the list of all recipients' email addresses
msg['From'] = me
msg['To'] = ', '.join(family)
msg.preamble = 'Our family reunion'

# Open the files in binary mode.  Use imghdr to figure out the
# MIME subtype for each specific image.
for file in pngfiles:
    with open(file, 'rb') as fp:
        img_data = fp.read()
    msg.add_attachment(img_data, maintype='image',
                                 subtype=imghdr.what(None, img_data))

# Send the email via our own SMTP server.
with smtplib.SMTP('localhost') as s:
    s.send_message(msg)
开发者ID:1st1,项目名称:cpython,代码行数:31,代码来源:email-mime.py

示例3: or

# 需要导入模块: from email.message import EmailMessage [as 别名]
# 或者: from email.message.EmailMessage import preamble [as 别名]
    #print(i[-5:])
    if i == "" or (i[-5:] == "each:"):
        tmp2.remove(i)
#print(tmp2)

if "--mail" in sys.argv and int((len(tmp.split("\n"))-1)/4) > 2:
    import smtplib

    from email.message import EmailMessage
    from email.headerregistry import Address
    from email.utils import make_msgid

    sender = "[email protected]"
    receiv = "[email protected]"
    msg = EmailMessage()
    msg["From"] = Address("Davo-Arch10", "[email protected]")
    msg["To"] = Address("Yo mismo", "[email protected]")
    msg['Subject'] = "Wallpapers compared " + time.strftime("%d/%m/%Y %H:%M:%S")
    msg.preamble = "WTF"
    contenido = "Duplicados encontrados {}:\n\n".format(int((len(tmp.split("\n"))-1)/4)) + tmp
    msg.set_content(contenido)

    try:
        smtpObj = smtplib.SMTP('smtp.ddavo.me')
        smtpObj.send_message(msg)
        print("Successfully sent email")
        smtpObj.quit()
    except:
        print("Unable to send email")
        raise
开发者ID:daviddavo,项目名称:Scripts,代码行数:32,代码来源:PyCompare.py


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