#gmail_send/settings.py
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'olee.techs@gmail.com'
EMAIL_HOST_PASSWORD = 'jzsbfkxvmxiabwow' #past the key or password app here
EMAIL_PORT = 587
EMAIL_USE_TLS = True
DEFAULT_FROM_EMAIL = 'from oleetech'
Email Host Password
goto manage your google account
Select Security
Select App Password
Login With Password
Click Select App And Set App name .
Copy The Code And Past Settings.py EMAIL_HOST_PASSWORD
আমরা যদি ইমেইল পাঠানোর সময় আমাদের প্রজেক্ট এর assets/media ফোল্ডার থেকে কোন ফাইল অ্যাটাচ করে দিতে চাই তাহলে settings.py ফাইলে media ইউআরএল সেটআপ করে দিতে হবে।
from django.core.mail import EmailMessage
from django.http import HttpResponse
from django.shortcuts import render
def send_email(request):
subject = 'Email with attachment'
message = 'Please see the attached file.'
from_email = 'your_email@gmail.com'
recipient_list = ['recipient@example.com']
email = EmailMessage(subject, message, from_email, recipient_list)
# email.attach_file('Python_module.pdf') # Replace with the actual path to the attachment
email.send(fail_silently=False)
return render(request, 'sendemail/email_sent.html')
urls.py
from django.urls import path
from . import views
urlpatterns = [
path('sendemail', views.send_email, name='send_email'),
]
Templates
templates/sendemail/email_sent.html
After Success Mail Sent Show Message in this Template
<html>
<head>
<title>Email sent</title>
</head>
<body>
<h1>Email sent</h1>
<p>Your email has been sent.</p>
</body>
</html>