config.rst 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. .. _config-gmail:
  30. Gmail
  31. -----
  32. In order to send emails using Gmail, you need to:
  33. - Set up `2-step verification <https://support.google.com/accounts/answer/185839>`_ (if not already)
  34. - Generate `an App password <https://support.google.com/accounts/answer/185833>`_:
  35. - Go to your `Google account <https://myaccount.google.com/>`_
  36. - Go to *Security*
  37. - Go to *App passwords*
  38. - Generate a new one (you may use custom app and give it a custom name)
  39. When you have your application password you can use Red Mail's gmail object that has the Gmail
  40. server pre-configured:
  41. .. code-block:: python
  42. from redmail import gmail
  43. gmail.user_name = 'example@gmail.com' # Your Gmail address
  44. gmail.password = '<APP PASSWORD>'
  45. # And then you can send emails
  46. gmail.send(
  47. subject="Example email",
  48. receivers=['you@example.com'],
  49. text="Hi, this is an email."
  50. )
  51. .. _config-outlook:
  52. Outlook
  53. -------
  54. You may also send emails from MS Outlook. To do so, you just need to have a Microsoft
  55. account. There is a pre-configured sender which you may use:
  56. .. code-block:: python
  57. from redmail import outlook
  58. outlook.user_name = 'example@hotmail.com'
  59. outlook.password = '<YOUR PASSWORD>'
  60. # And then you can send emails
  61. outlook.send(
  62. subject="Example email",
  63. receivers=['you@example.com'],
  64. text="Hi, this is an email."
  65. )