我对如何使用它有疑问
SMTP.sendmail(from_addr, to_addrs, msg[, mail_options, rcpt_options])
这是我的代码:
import sys
import os
import re
from smtplib import SMTP_SSL as SMTP
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText
SMTPserver = 'server.me.com'
sender = 'from@yyy.com'
destination = 'to@yyy.com'
recipient = ['rcp1@aaa.com', 'rcp2@aaa.com', 'rcp3@aaa.com']
USERNAME = 'user'
PASSWORD = 'pass'
text_subtype = 'plain'
content='This is a test for mail sending'
subject='Test'
try:
msg = MIMEMultipart()
msg = MIMEText(content, text_subtype)
msg['From'] = sender
msg['To'] = destination
msg['Cc'] = ', '.join(recipient)
msg['Subject']= subject
conn = SMTP(SMTPserver)
conn.login(USERNAME, PASSWORD)
try:
**conn.sendmail(sender, destination, msg.as_string())**
except Exception, exc:
sys.exit( "connection failed; %s" % str(exc) )
finally:
conn.close()
except Exception, exc:
sys.exit( "mail failed; %s" % str(exc) )
这是正确的语法或代码吗?我想要的是我也想将邮件发送到收件人列表,但我应该把它放在代码的哪里?