คือว่าผม ได้ทดลองส่ง e-mail โดยเรียก model ของ django ที่มีให้เราใช้คือ
1. from django.core.mail import send_mail
send_mail('Subject here', 'Here is the message.', 'from@example.com',
['to@example.com'], fail_silently=False)
from django.core.mail import EmailMultiAlternatives
subject, from_email, to = 'hello', 'from@example.com', 'to@example.com'
text_content = 'This is an important message.'
html_content = '
This is an important message.
'
msg = EmailMultiAlternatives(subject, text_content, from_email, [to])
msg.attach_alternative(html_content, "text/html")
msg.send()
คือผมได้ทดลองเรียกใช้ทั้ง โมดูล แล้วมันใช้ไม่ได้ทั้งสอง โมดูลเลยครับ (Error ครับ)
Traceback (most recent call last):
File "", line 1, in
File "/usr/local/lib/python2.6/dist-packages/django/core/mail.py", line 266, in send
return self.get_connection(fail_silently).send_messages([self])
File "/usr/local/lib/python2.6/dist-packages/django/core/mail.py", line 166, in send_messages
new_conn_created = self.open()
File "/usr/local/lib/python2.6/dist-packages/django/core/mail.py", line 131, in open
local_hostname=DNS_NAME.get_fqdn())
File "/usr/lib/python2.6/smtplib.py", line 239, in init
(code, msg) = self.connect(host, port)
File "/usr/lib/python2.6/smtplib.py", line 295, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "/usr/lib/python2.6/smtplib.py", line 273, in _get_socket
return socket.create_connection((port, host), timeout)
File "/usr/lib/python2.6/socket.py", line 512, in create_connection
raise error, msg
error: [Errno 111] Connection refused
ไม่ทราบว่าทำยังไงถึงจะทำให้มันสามารถทำงานได้ครับ
ขอบคุณครับ
กำหนดค่า EMAIL_HOST EMAIL_HOST_USER แล้วก็ EMAIL_HOST_PASSWORD หรือยังครับ ลองไปดูที่ไฟล์คอนฟิกก่อนนะครับ
http://www.tutorialspoint.com/python/python_sending_email.htm