Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

how to send emails in python

import smtplib
from email.message import EmailMessage

msg = EmailMessage()
msg.set_content('This is my message')

msg['Subject'] = 'Subject'
msg['From'] = "me@gmail.com"
msg['To'] = "you@gmail.com"

# Send the message via our own SMTP server.
server = smtplib.SMTP_SSL('smtp.gmail.com', 465)
server.login("me@gmail.com", "password")
server.send_message(msg)
server.quit()
Comment

send mail through python

# Import smtplib for the actual sending function
import smtplib

# Import the email modules we'll need
from email.message import EmailMessage

# Open the plain text file whose name is in textfile for reading.
with open(textfile) as fp:
    # Create a text/plain message
    msg = EmailMessage()
    msg.set_content(fp.read())

# me == the sender's email address
# you == the recipient's email address
msg['Subject'] = f'The contents of {textfile}'
msg['From'] = me
msg['To'] = you

# Send the message via our own SMTP server.
s = smtplib.SMTP('localhost')
s.send_message(msg)
s.quit()
Comment

python - sending mail

// Go to your gmail login 
// Go to ACCOUNT - SECURITY - LESS SECURE - TURN ON 
// You can only see the LESS SECURE option only if you don't have two factor authentication
// so if you have turn it off. 
------------------------------
// views.py inside the APP
// inside # Create your views here.
// def inquiry(request):

from django.core.mail import send_mail
from django.contrib.auth.models import User
from django.core.mail import send_mail

admin_info = User.objects.get(is_superuser=True)
admin_email = admin_info.email
send_mail(
    'New Car Inquiry',
    'You have a new inquiry for the car' + car_title + '. Please login to your admin panel for more info.',
    'active gmail account here ',
    ['admin_email'],
    fail_silently=False,
)

// settings.py 
// email sending
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST_USER = 'active gmail account here'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_HOST_PASSWORD = 'email password is here '

// to do the testing go to TERMINAL 
// First is:  
 python manage.py shell 

// Second is: 
 from django.core.mail import send_mail
 
// Third is: 

send_mail('django test mail', 'this is the body', 'active gmail account here', ['active gmail account here'], fail_silently=False)

// if the OUTPUT is 1, then the message sent successfully 
// to to your gamail to check if you received it. 
Comment

PREVIOUS NEXT
Code Example
Python :: tkinter asksaveasfile 
Python :: python get ids from array of objects 
Python :: np.zero 
Python :: python is ascii 
Python :: python get output 
Python :: python csv find specific string 
Python :: hh:mm to mins in python 
Python :: how to iterate a list in reverse order in python with index 
Python :: python check if string contains number 
Python :: python cheat 
Python :: função anonima python 
Python :: import csv 
Python :: dict python 
Python :: keras.datasets no module 
Python :: python get time executed by function 
Python :: Amazon price tracker in Python 
Python :: how to average only positive number in array numpy 
Python :: pandas df count values less than 0 
Python :: set comprehension 
Python :: multiprocessing while applying a function in pandas 
Python :: python standard normal cumulative distribution 
Python :: open file in python 
Python :: django 3 create async rest api 
Python :: winsound python 
Python :: pd df merge 
Python :: find item in list 
Python :: slicing in python list 
Python :: access element from list python 
Python :: python dataframe reihe anzeigen 
Python :: password protected cmd python 
ADD CONTENT
Topic
Content
Source link
Name
6+2 =