Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/21.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
Email Python2.7/Windows:发送SMTP电子邮件的非常奇怪的行为_Email_Python 2.7 - Fatal编程技术网

Email Python2.7/Windows:发送SMTP电子邮件的非常奇怪的行为

Email Python2.7/Windows:发送SMTP电子邮件的非常奇怪的行为,email,python-2.7,Email,Python 2.7,这完全把我难住了。下面是两个发送电子邮件的简单例程。第一个成功,第二个成功,但有一些小的异常捕获锁定,Python Cntl-C不会终止会话。此外,我已确定用于主题行的报价类型很重要。所以如果我使用 msg['Subject'] = "Random text" 电子邮件将失败,但是 msg['Subject'] = 'Random text' 这成功了 有人能给黑暗照点光吗 例1 import smtplib from email.mime.text import MIMEText addr

这完全把我难住了。下面是两个发送电子邮件的简单例程。第一个成功,第二个成功,但有一些小的异常捕获锁定,Python Cntl-C不会终止会话。此外,我已确定用于主题行的报价类型很重要。所以如果我使用

msg['Subject'] = "Random text"
电子邮件将失败,但是

msg['Subject'] = 'Random text'
这成功了

有人能给黑暗照点光吗

例1

import smtplib
from email.mime.text import MIMEText
addr = "10.0.0.178"
From = "me@somewhere.net"
recip = ["me@somewherelese.net","foo@bar.net"]
msg = "Message Body"
send_email(recip,"Subject Line",msg)

def send_email(To,Subj,Mess):
    msg = MIMEText(Mess)
    msg["Subject"] = Subj
    msg['From'] = From
    s = smtplib.SMTP(addr)
    for entry in To:
        msg['To'] = entry
        s.sendmail(From, [entry], msg.as_string())
    s.quit()
例2:

import smtplib
from email.mime.text import MIMEText
addr = "10.0.0.178"
From = "me@somewhere.net"
recip = ["me@somewherelese.net","foo@bar.net"]
msg = "Message Body"
send_email(recip,"Subject Line",msg)

def send_email(To,Subj,Mess):
    msg = MIMEText(Mess)
    msg["Subject"] = Subj
    msg['From'] = From
    s = smtplib.SMTP(addr)
    for entry in To:
        msg['To'] = entry
        try:
            s.sendmail(From, [entry], msg.as_string())
        except:
            print "Error sending email"
    s.quit()

你有没有想过?