相关疑难解决方法(0)

如何用Python发送电子邮件?

此代码可以正常工作并向我发送电子邮件:

import smtplib
#SERVER = "localhost"

FROM = 'monty@python.com'

TO = ["jon@mycompany.com"] # must be a list

SUBJECT = "Hello!"

TEXT = "This message was sent with Python's smtplib."

# Prepare actual message

message = """\
From: %s
To: %s
Subject: %s

%s
""" % (FROM, ", ".join(TO), SUBJECT, TEXT)

# Send the mail

server = smtplib.SMTP('myserver')
server.sendmail(FROM, TO, message)
server.quit()
Run Code Online (Sandbox Code Playgroud)

但是,如果我尝试将其包装在这样的函数中:

def sendMail(FROM,TO,SUBJECT,TEXT,SERVER):
    import smtplib
    """this is some test documentation in the function"""
    message = """\
        From: %s
        To: …
Run Code Online (Sandbox Code Playgroud)

python email function smtplib

155
推荐指数
8
解决办法
26万
查看次数

标签 统计

email ×1

function ×1

python ×1

smtplib ×1