[Answered ]-How to use an email URL with a password which contains slash character of `/`

1👍

Initially, normalize your password part (or the part that contains the slash)

In [2]: from urllib.parse import quote

In [3]: pwd = "BFB6UvkMgn9dniEGQZc/xM/KDS9Agc/S2"

In [4]: quote(pwd, safe="")
Out[4]: 'BFB6UvkMgn9dniEGQZc%2FxM%2FKDS9Agc%2FS2'

Now, we have got the normalized password string. Then, replace the password part of the URL with this new password. So, it will become as,

export EMAIL_URL="smtp://AKIAYZT73XCKGD:BFB6UvkMgn9dniEGQZc%2FxM%2FKDS9Agc%2FS2@email-smtp.us-east-2.amazonaws.com:587/?tls=True"

Example

In [16]: from urllib.parse import unquote

In [17]: env("EMAIL_URL")
Out[17]: 'smtp://AKIAYZT73XCKGD:BFB6UvkMgn9dniEGQZc%2FxM%2FKDS9Agc%2FS2@email-smtp.us-east-2.amazonaws.com:587/?tls=True'

In [18]: env.email_url('EMAIL_URL')
Out[18]: 
{'EMAIL_FILE_PATH': '',
 'EMAIL_HOST_USER': 'AKIAYZT73XCKGD',
 'EMAIL_HOST_PASSWORD': 'BFB6UvkMgn9dniEGQZc/xM/KDS9Agc/S2',
 'EMAIL_HOST': 'email-smtp.us-east-2.amazonaws.com',
 'EMAIL_PORT': 587,
 'EMAIL_BACKEND': 'django.core.mail.backends.smtp.EmailBackend',
 'OPTIONS': {'TLS': 'True'}}

In [19]: unquote(env("EMAIL_URL"))
Out[19]: 'smtp://AKIAYZT73XCKGD:BFB6UvkMgn9dniEGQZc/xM/KDS9Agc/S2@email-smtp.us-east-2.amazonaws.com:587/?tls=True'
👤JPG

0👍

From dj-email-url docs.

To use characters that have a special meaning in an URL (think of &)
you should use percent encoding. For example, m&m would become
m%26m.

Because the percent character itself (%) serves as the indicator for
percent-encoded octets, it must be percent-encoded as %25.

>>> from urllib.parse import quote_plus
>>> import dj_email_url
>>> quote_plus("!@#$%^&*") '%21%40%23%24%25%5E%26%2A'
>>> dj_email_url.parse("smtp://user:%21%40%23%24%25%5E%26%2A@localhost")["EMAIL_HOST_PASSWORD"]
'!@#$%^&*' ```

Leave a comment