1
0

config.rst 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. Configuring for Different Providers
  2. ===================================
  3. Sending emails from different email providers is easy.
  4. If you have your own SMTP server, you just need to
  5. set the host address, port and possibly the credentials.
  6. There are also pre-configured sender instances for
  7. common email providers:
  8. =================== =================== ================== ====
  9. Provider Sender instance Host Port
  10. =================== =================== ================== ====
  11. Gmail (Google) ``redmail.gmail`` smtp.gmail.com 587
  12. Outlook (Microsoft) ``redmail.outlook`` smtp.office365.com 587
  13. =================== =================== ================== ====
  14. To use them, you may need to configure the account (see below)
  15. and then you can use the sender:
  16. .. code-block:: python
  17. from redmail import outlook
  18. outlook.user_name = 'example@hotmail.com'
  19. outlook.password = '<YOUR PASSWORD>'
  20. outlook.send(
  21. subject="Example email",
  22. receivers=['you@example.com'],
  23. text="Hi, this is an email."
  24. )
  25. .. note::
  26. Often the email providers don't allow changing the sender address
  27. to something else than what was used to log in. Therefore, changing
  28. the ``sender`` argument often has no effect.
  29. .. note::
  30. By default, Red Mail uses STARTTLS which should be suitable for majority of cases
  31. and the pre-configured ports should support this. However, in some cases you may
  32. need to use other protocol and port. In such case, you may override the ``sender.port``
  33. and ``sender.cls_smtp`` attributes. Read more about configuring different protocols
  34. from :ref:`config-smtp`.
  35. .. _config-gmail:
  36. Gmail
  37. -----
  38. In order to send emails using Gmail, you need to:
  39. - Set up `2-step verification <https://support.google.com/accounts/answer/185839>`_ (if not already)
  40. - Generate `an App password <https://support.google.com/accounts/answer/185833>`_:
  41. - Go to your `Google account <https://myaccount.google.com/>`_
  42. - Go to *Security*
  43. - Go to *App passwords*
  44. - Generate a new one (you may use custom app and give it a custom name)
  45. When you have your application password you can use Red Mail's gmail object that has the Gmail
  46. server pre-configured:
  47. .. code-block:: python
  48. from redmail import gmail
  49. gmail.user_name = 'example@gmail.com' # Your Gmail address
  50. gmail.password = '<APP PASSWORD>'
  51. # And then you can send emails
  52. gmail.send(
  53. subject="Example email",
  54. receivers=['you@example.com'],
  55. text="Hi, this is an email."
  56. )
  57. .. _config-outlook:
  58. Outlook
  59. -------
  60. You may also send emails from MS Outlook. To do so, you just need to have a Microsoft
  61. account. There is a pre-configured sender which you may use:
  62. .. code-block:: python
  63. from redmail import outlook
  64. outlook.user_name = 'example@hotmail.com'
  65. outlook.password = '<YOUR PASSWORD>'
  66. # And then you can send emails
  67. outlook.send(
  68. subject="Example email",
  69. receivers=['you@example.com'],
  70. text="Hi, this is an email."
  71. )