Note that there are some explanatory texts on larger screens.

plurals
  1. POMysterious issue with Django + uWSGI + send email
    primarykey
    data
    text
    <p>I'm here to write you after about 1.5 hour of hard debugging.</p> <p><br> First of all, these are the interested files:</p> <h3><code>/project/app/utils.py</code></h3> <pre><code>from django.core.mail import EmailMultiAlternatives import threading class EmailThread(threading.Thread): def __init__(self, subject, body, from_email, recipient_list, fail_silently, html): self.subject = subject self.body = body self.recipient_list = recipient_list self.from_email = from_email self.fail_silently = fail_silently self.html = html threading.Thread.__init__(self) def run(self): msg = EmailMultiAlternatives(self.subject, self.body, self.from_email, self.recipient_list) if self.html: msg.attach_alternative(self.html, "text/html") print "sending message" msg.send(self.fail_silently) print "sent." def send_html_mail(subject, body, from_email, recipient_list, fail_silently=False, html=None, *args, **kwargs): EmailThread(subject, body, from_email, [recipient_list], fail_silently, html).start() </code></pre> <h3><code>/project/app/views.py</code></h3> <pre><code>[...] import utils def my_view(request): [...] utils.send_html_mail('subject', '&lt;h1&gt;cool things.&lt;/h1&gt;', 'Test &lt;test@example.org&gt;', 'my_email@example.org', html='&lt;h1&gt;cool things.&lt;/h1&gt;') </code></pre> <h3><code>/project/app/settings.py</code></h3> <pre><code># I use Amazon SES [...] EMAIL_BACKEND = 'backends.smtp.SSLEmailBackend' EMAIL_HOST = 'amazon-server' EMAIL_PORT = 465 EMAIL_HOST_USER = 'user' EMAIL_HOST_PASSWORD = 'pass' EMAIL_USE_TLS = True [...] </code></pre> <h3><code>/project/backends/smtp.py</code></h3> <pre><code># taken from https://gist.github.com/1486891 import smtplib from django.core.mail.utils import DNS_NAME from django.core.mail.backends.smtp import EmailBackend class SSLEmailBackend(EmailBackend): def open(self): if self.connection: return False try: self.connection = smtplib.SMTP_SSL(self.host, self.port, local_hostname=DNS_NAME.get_fqdn()) if self.username and self.password: self.connection.login(self.username, self.password) return True except: if not self.fail_silently: raise </code></pre> <p>Ok, now the problem:</p> <p>in localhost:</p> <ul> <li>sending the email from the view <strong>works</strong></li> <li>sending the email from the django shell <strong>works</strong></li> </ul> <p>in the deploy app on my server:</p> <ul> <li>sending the email from the view <strong>DOESN'T WORKS</strong></li> <li>sending the email from the django shell <strong>works</strong></li> </ul> <p>Django shell output in <strong>localhost</strong>:</p> <pre><code># utils.send_html_mail('subject', '&lt;h1&gt;cool things.&lt;/h1&gt;', 'Test &lt;test@example.org&gt;', 'my_email@example.org', html='&lt;h1&gt;cool things.&lt;/h1&gt;') sending email sent. </code></pre> <p>Django shell output in <strong>deploy app</strong>:</p> <pre><code># utils.send_html_mail('subject', '&lt;h1&gt;cool things.&lt;/h1&gt;', 'Test &lt;test@example.org&gt;', 'my_email@example.org', html='&lt;h1&gt;cool things.&lt;/h1&gt;') sending email </code></pre> <p>Same code, same commit. The problem is in the method <code>msg.send(self.fail_silently)</code> just before the <code>print "sent."</code> probably, but what is it? I don't have ideas.</p> <p>And you?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload