1
0

client.rst 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. .. _config-smtp:
  2. Configuring SMTP Client
  3. =======================
  4. Often the default client setup is enough but sometimes it may become necessary to get more control
  5. of the connection with your SMTP server. In this discussion we discuss ways to customize the connection.
  6. By default Red Mail uses `STARTTLS <https://en.wikipedia.org/wiki/Opportunistic_TLS>`_ or opportunistic
  7. TLS in connecting to the SMTP server. You may also change this if needed by changing the
  8. ``cls_smtp`` to other SMTP client classes from ::stdlib:`smtplib <smtplib.html>`
  9. in standard library.
  10. .. note::
  11. Extra keyword arguments in :class:`.EmailSender` initiation are passed to the SMTP client.
  12. Please see the documentation of the SMTP client you are seeking.
  13. STARTTLS
  14. --------
  15. By default, Red Mail uses `STARTTLS <https://en.wikipedia.org/wiki/Opportunistic_TLS>`_
  16. which is configured as this:
  17. .. code-block:: python
  18. from redmail import EmailSender
  19. from smtplib import SMTP
  20. email = EmailSender(
  21. host="smtp.example.com",
  22. port=587,
  23. cls_smtp=SMTP,
  24. use_starttls=True
  25. )
  26. SMTP TLS
  27. --------
  28. You may also continue using TLS:
  29. .. code-block:: python
  30. from redmail import EmailSender
  31. email = EmailSender(
  32. host="smtp.example.com",
  33. port=587,
  34. use_starttls=False
  35. )
  36. SMTP SSL
  37. --------
  38. To use SSL:
  39. .. code-block:: python
  40. from redmail import EmailSender
  41. from smtplib import SMTP_SSL
  42. email = EmailSender(
  43. host="smtp.example.com",
  44. port=587,
  45. cls_smtp=SMTP_SSL,
  46. )
  47. You may also pass the SSL context:
  48. .. code-block:: python
  49. from redmail import EmailSender
  50. from smtplib import SMTP_SSL
  51. from ssl import SSLContext
  52. email = EmailSender(
  53. host="smtp.example.com",
  54. port=587,
  55. cls_smtp=SMTP_SSL,
  56. context=SSLContext(...)
  57. )
  58. LMTP
  59. ----
  60. To use LMTP:
  61. .. code-block:: python
  62. from redmail import EmailSender
  63. from smtplib import LMTP
  64. email = EmailSender(
  65. host="smtp.example.com",
  66. port=587,
  67. cls_smtp=LMTP
  68. )