I'm trying to send email with Django - python

I'm trying to send email with Django but i keep getting SMTPConnectError
ErrorMessage
[Views.pysettings.py

Although you should get better information about your problem, but I though you could see SMTP settings of your email/gmail or etc.

Related

Django is sending me an email about "Invalid HTTP_HOST header"

I have website that using django on DigitialOcean. Django is sending me an email with title Invalid HTTP_HOST header: 'url.ml'. You may need to add 'url' to ALLOWED_HOSTS. But I don't want to add this, I added my own domains and ip address.
I have list of questions
Why is django sending me this email?
Bots are attacking to my site?
If so how they do that?
How can I prevent this?
As specified in the docs,
When DEBUG is False, Django will email the users listed in the ADMINS
setting whenever your code raises an unhandled exception and results
in an internal server error (HTTP status code 500). This gives the
administrators immediate notification of any errors. The ADMINS will
get a description of the error, a complete Python traceback, and
details about the HTTP request that caused the error.
So, I guess email comes from this. If your are interested in getting more detailed trace on 500 errors, you can have a look on Sentry, which his quite useful.
Now, regarding your error: url.ml I can't find any IP on this domain, but it's quite easy to had this header manually.
If you want to go deeper, you can go check your NGINX Log, aiming for IP sending those kind of requests: It might be some kind of DigitalOcean monitoring utilities, some kind of attack, you will need to get more details about that.

Sending from gmail with smtplib

I'm attempting to use smtplib to set up a python script that will email out alert notifications. I don't need anything fancy, so I figured I'd stick with the basics and use SMTP for my messages. Following one of the many available online examples, my attempt to do so begins
server = smtplib.SMTP('smtp.gmail.com:587')
server.starttls()
server.login('username','password')
but at this point fails with an SMTPAuthenticationError 534, telling me to log on via my web browser. When I so, gmail has emailed me saying the sign in failed because it came from "an app that doesn't meet modern security standards."
I've seen some people having similar problems solved by changing their gmail account to accept logon from less secure apps, but did this myself and continued to get the same error message.
So is plain old SMTP not going to cut it and I need to get fancy? What am I doing wrong, or what can I do instead to make this work?
As it turns out, my attempts to set gmail to accept logon from less secure apps had (for whatever reason) not taken the first time I tried. Going to https://myaccount.google.com/security?pli=1 and turning this setting on allowed me to access successfully.
The comments pointing me towards oauth2 and app passwords are most helpful though, and I now that I've accomplished the bare bones I may look into those for more robust long-term approaches. Thank you!

Python / Django | How to store sent emails?

I was wondering how can I store sent emails
I have a send_email() function in a pre_save() and now I want to store the emails that have been sent so that I can check when an email was sent and if it was sent at all.
I think the easiest way before messing up with middleware or whatever is to simply create a model for your logged emails and add a new record if send was successful.
Another way to look at it: send the mail to your backup email account ex: backup#yourdomain.com. So you can store the email, check if the email is sent or not.
Other than that, having an extra model for logged emails is a way to go.
I would suggest making use of an existing django mail app.
django-mailer may do the trick. It has a message log.
I think it is best not to send email directly from views, your views then won't get blocked if your mail server happens not to be functioning, so that's another reason to use something like this.

GAE Python - Receive incoming email on #mydomain.com address

I am setting up a GAE app that triggers certain tasks by an email from the user. I've set up the app using the information on this page: https://developers.google.com/appengine/docs/python/mail/receivingmail. Everything works as expected, however, I would like to send the emails to a #mydomain.com email address, instead of a #myapp.appspotmail.com email address.
Currently I am using an automatic forward on the email address to get around this, however once this scales I expect to reach the daily limit on forwarded messages at some point (10.000 according to https://support.google.com/a/answer/166852?hl=en).
Is there any way that I can integrate my app with the #mydomain.com email address to prevent this from happening? Or would you know another solution for this issue?
Probably, you should check recently implemented GAE integration with SendGrid, I haven't used it myself (use the same solution you've described with email forwarding), but looks like it can help.
As LA_ mentioned, SendGrid offers a webhook for this. I ended up using MailGun, which has a similar functionality and calls a HTTP POST to my app whenever an email comes in on my #mydomain.com address.

Sending Mail with low level python mail api (Google App Engine)

I need to embed images in email but GAE email api wont let me. So i need to use low level python api but i dont know how to authenticate with it. Is it possible? And if its possible simple example like sending text/plain email can be enough.
Thanks.
In GAE, with Mail API, you can embed image using message.html instead message.body.
This is the related docs email message fields

Categories

Resources