> For the complete documentation index, see [llms.txt](https://olee-tech.gitbook.io/django/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://olee-tech.gitbook.io/django/send-email/send-email-from-gmail.md).

# Send Email From Gmail

### Settings.py

```python
#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&#x20;

<figure><img src="https://664948176-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FdX27l90MHtjXhtBupXys%2Fuploads%2FH0NzQlEGgFNCclvs1cfF%2FScreenshot_1.png?alt=media&amp;token=90ad4591-88f5-45af-95f1-aa4c58647f8c" alt=""><figcaption></figcaption></figure>

**Select Security**

<figure><img src="https://664948176-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FdX27l90MHtjXhtBupXys%2Fuploads%2FIGMGK9qbqLLkWJhEBWvb%2FScreenshot_2.png?alt=media&amp;token=a23d8f2d-f64b-4e8c-8935-5310350d80bd" alt=""><figcaption></figcaption></figure>

### Select App Password

<figure><img src="https://664948176-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FdX27l90MHtjXhtBupXys%2Fuploads%2F1BDnPiQ8PuRcDkOJRZQ5%2FScreenshot_3.png?alt=media&amp;token=556ea014-92e3-4c07-9e34-fe02c519c95d" alt=""><figcaption></figcaption></figure>

Login With Password

<figure><img src="https://664948176-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FdX27l90MHtjXhtBupXys%2Fuploads%2FI7NPoYoTA1pbVmTKQEbe%2FScreenshot_4.png?alt=media&amp;token=0a4450f3-1239-4f37-a22a-95eb8f96a8be" alt=""><figcaption></figcaption></figure>

Click Select App And Set App name .&#x20;

<figure><img src="https://664948176-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FdX27l90MHtjXhtBupXys%2Fuploads%2FfCauZhsIL53KOhD3OSVJ%2FScreenshot_5.png?alt=media&amp;token=2381f168-c640-4df4-ba2b-f6e113a23e3b" alt=""><figcaption></figcaption></figure>

Copy The Code And Past Settings.py  EMAIL\_HOST\_PASSWORD

<figure><img src="https://664948176-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FdX27l90MHtjXhtBupXys%2Fuploads%2FMETUxX841LIm7xo9pHDY%2FScreenshot_6.png?alt=media&amp;token=a848f2e6-46b2-474c-9d33-f7d3b8b08cb3" alt=""><figcaption></figcaption></figure>

আমরা যদি ইমেইল পাঠানোর সময় আমাদের প্রজেক্ট এর assets/media ফোল্ডার থেকে কোন ফাইল অ্যাটাচ করে দিতে চাই তাহলে settings.py ফাইলে media ইউআরএল সেটআপ করে দিতে হবে।

**settings.py**

```
STATIC_URL = 'static/'
STATICFILES_DIRS = [
    BASE_DIR / 'static',
]
STATIC_ROOT=(BASE_DIR/ "assets/")
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'assets/media/')
```

### Views.py

```python
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

```python

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

<html>
    <head>
        <title>Email sent</title>
    </head>
    <body>
        <h1>Email sent</h1>
        <p>Your email has been sent.</p>
    </body>
</html>

```
