How can I change email sender's name in django - django

I'm creating email system in my django project and faced to next question:
Send email from custom email sender name, f.e. sending email from gmail(btw it works in my project) requires sending messages only from gmail account, same thing with smtp-pulse, sendgrid and etc. .
My question is: May I use any of already configured smtp servers in my case, or I only need to create my own using smtplib(f.e) and configure it?
Tried:
DEFAULT_FROM_EMAIL = 'support#site.com'
SERVER_EMAIL = 'support#site.com'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 2525
EMAIL_USE_TLS = False
EMAIL_HOST_USER = 'user#gmail.com'
EMAIL_HOST_PASSWORD = 'password'
This one doesn't work.
Same with mail.ru/smtp-pulse.com

Try
DEFAULT_FROM_EMAIL = "Site Support <support#site.com>"

Related

SMTPAuthenticationError when sending gmail

I am having this error: smtplib.SMTPAuthenticationError: (535, b'5.7.8 Username and Password not accepted. Learn more at\n5.7.8 https://support.google.com/mail/?p=BadCredentials ij28-20020a170902ab5c00b00163efcd50bdsm1197936plb.94 - gsmtp') when I try to send a gmail in my registration app
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'repository0612#gmail.com'
EMAIL_HOST_PASSWORD = '****************'
EMAIL_PORT = 587
I read in some other related forums that you just have to turn on the less secure apps in your google account settings but google already disabled that particular setting. I also tried turning off the 2-way authentication and my EMAIL_HOST_USER and EMAIL_HOST_PASSWORD are as the same as my email and password. What else should I do to solve this problem?
This feature is no longer supported as of May 30th, 2022. See https://support.google.com/accounts/answer/6010255?hl=en&visit_id=637896899107643254-869975220&p=less-secure-apps&rd=1#zippy=%2Cuse-an-app-password
https://stackoverflow.com/a/27515833/19312416
So for new users we wont be able to use less secure app due to a new update, but there is nothing to worry.
In gmail after you allow 2 step authendication you will get a feature named app passsword you can use this.
Go to app password > provide name > copy password.
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_USE_TLS = True
EMAIL_PORT = 587
EMAIL_HOST_USER =
EMAIL_HOST_PASSWORD = "paste that password"
this will work!
i believe your problem with code, try my function, it works with gmail, without additional settings
import smtplib
from email.mime.text import MIMEText
def email_sender(to_email, theme, message):
sender = "example#gmail.com"
password = "mypassword"
body = message
# make up message
msg = MIMEText(body)
msg['Subject'] = theme
msg['From'] = sender
msg['To'] = ", ".join(to_email)
#sending
session = smtplib.SMTP('smtp.gmail.com', 587)
session.starttls()
session.login(sender, password)
send_it = session.sendmail(sender, to_email, msg.as_string())
session.quit()
Thanks for the help guys. It already works by using the generated app password in my google account instead of using my own created password in EMAIL_HOST_PASSWORD

Sending emails in Django with NameCheap email account

I set up an email account with NameCheap that I use with my Django app. Below is my email configuration based on information provided by NameCheap
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'mail.privateemail.com'
EMAIL_PORT = 465
EMAIL_HOST_USER = 'news#mydomain.com'
EMAIL_HOST_PASSWORD = os.getenv('EMAIL_PASSWORD')
EMAIL_USE_SSL = True
DEFAULT_FROM_EMAIL = 'WebsiteTitle <news#mydomain.com>'
Now when I use send_mail() django function (eg. after registration) it is like playing roulette - one time it works properly and sends out an email, another time it throws an error saying
SMTPServerDisconnected at /reset-password/
Connection unexpectedly closed
As if something was wrong with my email configuration.
Do you have any idea what might cause it or how to try to fix it or debug it? Is it more likely NameCheap or Django?

Django -Email is appearing in console instead of being sent to recipient

I am using a business email for my website. Website has two parts, One is "Contact Us" form where email will be sent to my [business email]. Second part requires email to be sent from [business email] to customers emails.
I have set up django mail as per documentation:
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'cp1.mywebsitebox.com'
EMAIL_HOST_USER = '*********'
EMAIL_HOST_PASSWORD = '********'
EMAIL_PORT = 26
DEFAULT_FROM_EMAIL = '*******'
Issue is that, first part goes well. Email recieves successfully at [business email] but second part is totally not working. Instead of being sent to recipient, it appears only in console.
Can anyone suggest what the issue is?
it may be issue from your mailing server, can you try gmail server for testing
EMAIL_BACKEND = ‘django.core.mail.backends.smtp.EmailBackend’
EMAIL_HOST = ‘smtp.gmail.com’
EMAIL_USE_TLS = True
EMAIL_PORT = 587
EMAIL_HOST_USER = ‘your_account#gmail.com’
EMAIL_HOST_PASSWORD = ‘your account’s password’
and enable less secure app for testing
https://myaccount.google.com/lesssecureapps

unable to send email to other user emails account in django

i previously i was using gmail smtp to send mail**(working fine)** but now i created new account in sendgrid and im using free plan in my django project this my complete setting about send grid
EMAIL_HOST = 'smtp.sendgrid.net'
EMAIL_HOST_USER = 'apikey' # this is exactly the value 'apikey'
EMAIL_HOST_PASSWORD = 'SG.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' # this is API key
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
is any other settings required?? i am testing email using rest auth lib http://127.0.0.1:8000/rest-auth/password/reset/
is show msg like success": "Password reset e-mail has been sent."
but recipient did not received any mails but in sendgrid dashboard it is showing 9 or 10 etc msg delivered

Why does email be sent locally and not through server?

I'm working on a Django application.
I have set up all my required password reset views and corresponding pages.
In the final step I want to use Send Grid in my application to send the emails. I have the following setting s in my base.py file
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST_USER = 'codesniper99' # email id
EMAIL_HOST = 'smtp.sendgrid.net'
EMAIL_PORT = 587
EMAIL_HOST_PASSWORD = '****' #password
EMAIL_USE_TLS = True
where **** is my password for the username codesniper99 on sendgrid.com
But when I use the password reset function I get locally generated email to my account. Like when i put email for reset as akhilvaid21#gmail.com
I get this:
when I push my code to my production server and not local host then it doesn't work and no email is sent. What am I doing wrong?
Also how do I change the name of webmaster#localhost???
Make sure you have set DEFAULT_FROM_EMAIL and SERVER_EMAIL in your settings.
Many email providers will only let you send email from verified email addresses. It looks as if Sendgrid might be blocking emails because Django is using the default webmaster#localhost for DEFAULT_FROM_EMAIL.