librelist archives

« back to archive

Flask Mail Woes

Flask Mail Woes

From:
James Willson
Date:
2012-10-10 @ 12:40
Hi!
I posted a while back with help on my configs, I beleive they are sorted 
but im having a hard time moving forward. I was wondering if I could bug 
you for more help. 
This is my config:# MAIL SETTINGSMAIL_SERVER = 
'email-smtp.us-east-1.amazonaws.com'MAIL_PORT = 25MAIL_USE_TLS = 
TrueMAIL_USE_SSL = FalseMAIL_USERNAME = 'USER'MAIL_PASSWORD = 
'PASS'#MAIL_DEBUG = app.debugDEFAULT_MAIL_SENDER = NoneMAIL_DEBUG = 
FalseDEFAULT_MAIL_SENDER = NoneMAIL_FAIL_SILENTLY = False
This is the code that fires it:def send_confirmation_email(post):    if 
not post.email_invoice_address:        return False
    recipients = [post.email_invoice_address]    msg = Message('Posted 
juccessfully',                  body='Posted: %r' % post,
recipients=recipients)    try:        mail.send(msg)    except:  # Dont 
let SMTP errors take down the application. Should log error here        
return False    return True
Now, for the life of me I dont even know where to start debugging it, all 
I know is it doesnt work. The details in the config are correct, I know 
that much. Is there anything glaringly obvious wrong with this and how can
I move forward trying to debug this?
Thank you!
James 		 	   		  

Re: [flask] Flask Mail Woes

From:
Nigel Babu
Date:
2012-10-10 @ 13:15
On Wed, Oct 10, 2012 at 6:10 PM, James Willson
<james_willson@hotmail.com> wrote:
> Hi!
>
> I posted a while back with help on my configs, I beleive they are sorted but
> im having a hard time moving forward. I was wondering if I could bug you for
> more help.
>
> This is my config:
> # MAIL SETTINGS
> MAIL_SERVER = 'email-smtp.us-east-1.amazonaws.com'
> MAIL_PORT = 25
> MAIL_USE_TLS = True
> MAIL_USE_SSL = False
> MAIL_USERNAME = 'USER'
> MAIL_PASSWORD = 'PASS'
> #MAIL_DEBUG = app.debug
> DEFAULT_MAIL_SENDER = None
> MAIL_DEBUG = False
> DEFAULT_MAIL_SENDER = None
> MAIL_FAIL_SILENTLY = False
>
> This is the code that fires it:
> def send_confirmation_email(post):
>     if not post.email_invoice_address:
>         return False
>
>     recipients = [post. email_invoice_address]
>     msg = Message('Posted juccessfully',
>                   body='Posted: %r' % post,
>                   recipients=recipients)
>     try:
>         mail.send(msg)
>     except:  # Dont let SMTP errors take down the application. Should log
> error here
>         return False
>     return True
>
> Now, for the life of me I dont even know where to start debugging it, all I
> know is it doesnt work. The details in the config are correct, I know that
> much. Is there anything glaringly obvious wrong with this and how can I move
> forward trying to debug this?
>
> Thank you!
>
> James

Hi James,

The only glaringly obvious error I can spot is post.
email_invoice_address (you shouldn't have a space between the . and
e).  Not sure if that's a typo from your code or a typo from typing it
into email.  Anyway, can you remove the try and except blocks and see
if there are tracebacks when attempting to send email?

Regards
Nigel

Re: [flask] Flask Mail Woes

From:
Simon Sapin
Date:
2012-10-10 @ 13:21
Le 10/10/2012 15:15, Nigel Babu a écrit :
> The only glaringly obvious error I can spot is post.
> email_invoice_address (you shouldn't have a space between the . and
> e).  Not sure if that's a typo from your code or a typo from typing it
> into email.

Actually, white space before or after the dot for attribute access is 
valid Python syntax. (Although it can be bad style.)


> Anyway, can you remove the try and except blocks and see
> if there are tracebacks when attempting to send email?

This is more probably what is swallowing the error.

-- 
Simon Sapin

Re: [flask] Flask Mail Woes

From:
Erik Simmler
Date:
2012-10-10 @ 13:14
On Wed Oct 10 08:40:18 2012, James Willson wrote:
> MAIL_FAIL_SILENTLY = False

>     try:
>         mail.send(msg)
>     except:  # Dont let SMTP errors take down the application. Should
> log error here
>         return False
>     return True

You have fail silently turned off, which is good, but this except: is 
swallowing any errors. Without seeing your logging code I can't tell if 
it's properly recording the exception, but the first thing I'd do to 
debug is remove the try/except completely and see what flask-mail 
throws for exceptions.