你安装 turbomail
easy_install turbomail
在你的金字塔项目中创建一个文件(我把我的放在 lib 中),如下所示:
import turbomail
def send_mail(body, author,subject, to):
"""
parameters:
- body content 'body'
- author's email 'author'
- subject 'subject'
- recv email 'to'
"""
conf = {
'mail.on': True,
'mail.transport': 'smtp',
'mail.smtp.server': 'MAIL-SERVER:25',
}
turbomail.interface.start(conf)
message = turbomail.Message(
author = author,
to = to,
subject = subject,
plain = 'This is HTML email',
rich = body,
encoding = "utf-8"
)
message.send()
turbomail.interface.stop()
然后在您的控制器中,您只需像这样调用此函数:
#first import this function
from myproject.lib.mymail import send_mail
#some code...
body = "<html><head></head><body>Hello World</body></html>"
author = "mymail@example.com"
subject = "testing turbomail"
to = "mysecondmail@example.com"
send_mail(body, author, subject, to)