當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。