你需要一些关于python smtplib的帮助。代码按以下方式工作
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
sender = "sender@abc.com"
subject = "Test Email"
to_list = ["recipient@xyz.com"]
cc_list = ["sender@abc.com"]
bcc_list = ["sender@abc.com"]
msg = MIMEMultipart('alternative')
body = "<B> This is </B> a test message"
emailbody = MIMEText(body, 'html')
msg.attach(emailbody)
msg['Subject'] = subject
msg['From'] = sender
msg['To'] = ",".join(to_list)
msg['Cc'] = ",".join(cc_list)
recipients = to_list + cc_list + bcc_list
s = smtplib.SMTP('localhost')
s.sendmail(sender, recipients, msg.as_string())
代码有效,并且能够由收件人接收。但是,cc和/或密件抄送不会收到电子邮件,而是发送给自己。在linux2上使用Python 2.6.6 /(Red Hat 4.4.7-17)]
[编辑]
我有点孤立了这个问题。如果我使用xx@abc.com作为发件人,xx @ abc.com和xx@xyz.com将能够收到该电子邮件。但是,当我使用 xx@xyz.com 作为发件人时,只有 xx@abc.com 才能收到该电子邮件。这可能是SMTP服务器上的问题,还是我可以在smtplib中使用任何参数?以下是输出注意:我已经用xxxxxxxxxx :)替换了一些信息:
>>> s.sendmail(sender, toaddrs, msg.as_string())
send: 'ehlo [xxxxxxxxxx]\r\n'
reply: '250-xxxxxxxxxx\r\n'
reply: '250-PIPELINING\r\n'
reply: '250-SIZE 10240000\r\n'
reply: '250-VRFY\r\n'
reply: '250-ETRN\r\n'
reply: '250-ENHANCEDSTATUSCODES\r\n'
reply: '250-8BITMIME\r\n'
reply: '250 DSN\r\n'
reply: retcode (250); Msg: xxxxxxxxxx
PIPELINING
SIZE 10240000
VRFY
ETRN
ENHANCEDSTATUSCODES
8BITMIME
DSN
send: 'mail FROM:<xxxxxxxxxx> size=425\r\n'
reply: '250 2.1.0 Ok\r\n'
reply: retcode (250); Msg: 2.1.0 Ok
send: 'rcpt TO:<XXXXXXXXXXXX>\r\n'
reply: '354 End data with <CR><LF>.<CR><LF>\r\n'
reply: retcode (354); Msg: End data with <CR><LF>.<CR><LF>
data: (354, 'End data with <CR><LF>.<CR><LF>')
send: 'Content-Type: multipart/alternative;\r\n\tboundary="===============2153749063822088494=="\r\nMIME-Version: 1.0\r\nSubject: Test Email\r\nFrom: xxxxxxxxxx\r\nTo: xxxxxxxxxx\r\nCc: xxxxxxxxxx,xxxxxxxxxx.com\r\n\r\n--===============2153749063822088494==\r\nContent-Type: text/html; charset="us-ascii"\r\nMIME-Version: 1.0\r\nContent-Transfer-Encoding: 7bit\r\n\r\n<B> This is </B> a test message\r\n--===============2153749063822088494==--\r\n.\r\n'
reply: '250 2.0.0 Ok: queued as 173532000045\r\n'
reply: retcode (250); Msg: 2.0.0 Ok: queued as 173532000045
data: (250, '2.0.0 Ok: queued as 173532000045')
{}
提前致谢。