这是我的亚马逊 SES 的 python 代码:
import mimetypes
from email import encoders
from email.utils import COMMASPACE
from email.mime.multipart import MIMEMultipart
from email.mime.audio import MIMEAudio
from email.mime.base import MIMEBase
from email.mime.image import MIMEImage
from email.mime.text import MIMEText
from boto.ses import SESConnection
class SESMessage(object):
"""
Usage:
msg = SESMessage('from@example.com', 'to@example.com', 'The subject')
msg.text = 'Text body'
msg.html = 'HTML body'
msg.send()
"""
def __init__(self, source, to_addresses, subject, **kw):
self.ses = connection
self._source = source
self._to_addresses = to_addresses
self._cc_addresses = None
self._bcc_addresses = None
self.subject = subject
self.text = None
self.html = None
self.attachments = []
def send(self):
if not self.ses:
raise Exception, 'No connection found'
if (self.text and not self.html and not self.attachments) or \
(self.html and not self.text and not self.attachments):
return self.ses.send_email(self._source, self.subject,
self.text or self.html,
self._to_addresses, self._cc_addresses,
self._bcc_addresses,
format='text' if self.text else 'html')
else:
message = MIMEMultipart('alternative')
message['Subject'] = self.subject
message['From'] = self._source
if isinstance(self._to_addresses, (list, tuple)):
message['To'] = COMMASPACE.join(self._to_addresses)
else:
message['To'] = self._to_addresses
message.attach(MIMEText(self.text, 'plain'))
message.attach(MIMEText(self.html, 'html'))
根据amazon ses boto library ,我可以通过MIME标头发送 html 或文本或带有附件的电子邮件,但我如何提及普通文本或 html 邮件的标头?我需要从用户可以取消订阅的附加列表取消订阅链接。
如果我发送普通邮件,那么如果部分在那里运行,我将无法添加像 message['list-unsubscribe'] = " http://www.xyaz.com "这样的标题