これをどう使うかが問題
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) )
これは正しい構文またはコードですか? 私が欲しいのは、受信者のリストにもメールを送信したいということですが、コードのどこに配置すればよいですか?