Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/328.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python一次发送一行电子邮件_Python_Email - Fatal编程技术网

python一次发送一行电子邮件

python一次发送一行电子邮件,python,email,Python,Email,我的电子邮件程序将每行邮件作为单独的电子邮件发送,我想知道如何在一封电子邮件中发送所有邮件,当发送电子邮件时,程序将返回到开头 import smtplib from email.mime.text import MIMEText a = 1 while a == 1: print " " To = raw_input("To: ") subject = raw_input("subject: ") input_list = [] print "mess

我的电子邮件程序将每行邮件作为单独的电子邮件发送,我想知道如何在一封电子邮件中发送所有邮件,当发送电子邮件时,程序将返回到开头

import smtplib
from email.mime.text import MIMEText

a = 1
while a == 1:
    print " "
    To = raw_input("To: ")
    subject = raw_input("subject: ")
    input_list = []
    print "message: "
    while True:
        input_str = raw_input(">")
        if input_str == "." and input_list[-1] == "":
            break
        else:
            input_list.append(input_str)

    for line in input_list:

        # Create a MIME text message and populate its values
        msg = MIMEText(line)
        msg['Subject'] = subject
        msg['From'] = '123@example.com'
        msg['To'] = To

        server = smtplib.SMTP_SSL('server', 465)
        server.ehlo()
        server.set_debuglevel(1)
        server.ehlo()
        server.login('username', 'password')

        # Send a properly formatted MIME message, rather than a raw string
        server.sendmail('user@example.net', To, msg.as_string())
        server.close()
(需要多行的部分是在Paul Griffiths的帮助下制作的)

您正在这个循环中调用
server.sendmail

首先构建整个消息(在一个循环中),然后添加所有标题并发送消息

您正在这个循环中调用
server.sendmail

首先构建整个消息(在一个循环中),然后添加所有标题并发送消息

for line in input_list:

        # Create a MIME text message and populate its values
        msg = MIMEText(line)