Flask-Mail not sending emails, no error is being reported - flask

All, I'm trying to setup flask-mail to send notifications to my email when a user registers.
I'm getting no error messages from the script used to send the email, but nothing is actually being sent, or at least, nothing is being received.
Is there a log file which can show if an email was sent, rejected, or maybe if there was even a problem logging onto the server? How does on track this problem?
Any ideas here?

Flask-Email use smtplib which can set debug level: https://github.com/mattupstate/flask-mail/blob/master/flask_mail.py#L139. You can set it with MAIL_DEBUG = True or DEBUG = True. Also check that MAIL_SUPPRESS_SEND = False and TESTING = False.
With debug I can see in stdout mail progress: success, fail, recipients and etc.
See details: http://pythonhosted.org/Flask-Mail/#configuring-flask-mail.

tbicr has the most likely fix, check MAIL_SUPPRESS_SEND first.
What ended up burning me (being new to flask) is that when you instantiate your Mail() object, be sure it's after you've set your app.config values. The Mail() object doesn't go back and look at these values after the fact, so they will default to bad values. What's frustrating is that you won't see any errors when you try to send messages with the default/bad values. At least not as of my posting.

I know this post is from a while ago, but I just ran into the same issue. Like #tbicr mentioned make sure that app.testing is set to False. As it states in the Flask-Maildocs here:
"If the setting TESTING is set to True, emails will be suppressed. Calling send() on your messages will not result in any messages being actually sent."
This was exactly my problem. I implemented Google reCAPTCHA into one of my forms and the app.testing was set to True so I did not have to hit the reCAPTCHA box every time. By removing the app.testing or by setting it to False, the emails were able to be sent.

Related

sendgrid SENDGRID_ECHO_TO_STDOUT

Iam looking to use this pkg to send emails in my django app:
https://github.com/sklarsa/django-sendgrid-v5
and I see the field: SENDGRID_ECHO_TO_STDOUT and the description says:
will echo to stdout or any other file-like object that is passed to the backend via the stream kwarg.
I literally do not get what this means. My understanding was that if I set this to True, the email WONT be delivered but will be saved as a file and will output 1 in the terminal ?
However when I see this:https://simpleit.rocks/python/django/adding-email-to-django-the-easiest-way/
I think the guy manages to send emails even when this flag is set to True? Is that correct?
Sorry if this is a daft quetsion - I just do not understand this flag.
Should the flag be set to True or False in production?

Prevent django send_mail timimg attack

I have different REST-API views where I either send a mail (if an account exists) or do not send a mail.
For example, the user can input the email in the forgot-password form and a mail is sent if the account exists.
I am using from django.core.mail import send_mail to send the mail.
The problem is, that this takes some time, and so requests for valid emails are generally longer than requests for non-exiting emails.
This allows an attacker to compare the request times to find out if an account exists or not.
Is there any way that I can call send_mail() without sending the mail?
Or what would be the fix to make request times equally long for both cases?
Note: I could check how long send_mail() needs on average and wait this time if I do not send the mail. As the app runs on different servers with different configs, this can not be generally done in my case. I would rather not store the average execution time per server in a database to solve this.
It's a common practice to use celery for tasks that require some time to be finished. Celery will run a task in a separate thread and a user doesn't need to wait while it is finished. In your specific case what will happen if you use celery:
You send a task send_mail to celery and immediately return a successful response to a user.
Celery receives a task and runs it in a separate thread.
In this way, the response time for both cases will be the same.
So this is something similar to an issue I had, and my solution was actually to always send the email, but the email reads something like You tried to reset your password, but this email isn't registered to an account with us. if they don't have an account.
From a user's perspective, it can be annoying to have to wait for an email that may or may not arrive, and spend time checking spam/junk etc. Telling them they don't have an account with that email address is quicker and cleaner for them.
We saw a big drop in users enquiring with us about why they hadn't received a PW reset email.
(Sorry for not actually answering the question, I dislike it when people do this on SO but since I experienced the same issue, I thought I'd weigh in.)

Request Read Receipt with Python/Exchangelib?

My first post so please excuse any ignorance on my part. I have had great success with email automation using Exchangelib. I am curious to know if there is a configuration option to request a read or delivery receipt?
I have spent the last few days researching options but not having any luck.
You should be able to set the Message.is_read_receipt_requested boolean field. When set to True, you will get a read receipt when the is_read field of the received message is set to True, unless the receiver explicitly disabled sending read receipts.

Receiving complaints for SES transactional emails - are TiS notifications generated by filters?

We're doing everything we can think of to limit the number of complaints we receive and will immediately remove anyone who marks us as junk that does not need to receive our emails. However, the last handful of complaints we've received have come from transactional emails of people who are receiving our company's services and NEED to receive everything we send transactionally as a critical part of our service. (e.g. We are booking their travel on their behalf and we need to send them verification emails to confirm their booking details.)
We're assuming that most of these complaints are somehow either false positives or are being done on accident. One customer confirmed that they did not click the junk mail button but it ended up in their junk folder and they moved it to their inbox. Some questions:
Can a TiS complaint be triggered by any means other than the user manually marking an email as junk in their email client? (Can automatic spam filters trigger this complaint? AWS documentation specifies only clicking the junk button.)
Besides contacting each individual personally, what would you suggest we do? Our complaint rate is continuing to rise even though we are taking action on every one.

How to handle exceptions with cfmail?

In my project I am using <cfmail> to send an order confirmation to a user after successful creation of an order. I have got one doubt. If the mail server goes down during that time is there any way to handle that situation with cftry and cfcatch, or doesn't it handle those errors?
Normally if spoolenable is enabled the email will go to the spool and the page processes whether the mail actually gets sent or not as long as all the required fields are entered and valid.
https://wikidocs.adobe.com/wiki/display/coldfusionen/cfmail
Spool Enable details from Wiki
spoolenable
Optional
Whether to spool mail or always send it Immediately. Overrides the ColdFusion Administrator Spool mail messages to disk for delivery setting.
yes: saves a copy of the message until the sending operation is complete. Pages that use this option might run slower than the ones that use the No option.
no: queues the message for sending, without storing a copy until the operation is complete. If a delivery error occurs when this option is No, ColdFusion generates an Application exception and logs the error to the mail.log file.