33
33
34
34
35
35
class MailpitUser (NamedTuple ):
36
- """Mailpit user for authentication"""
36
+ """Mailpit user for authentication
37
+
38
+ Helper class to define a user for Mailpit authentication.
39
+
40
+ Is just a named tuple with username and password.
41
+
42
+
43
+ Example:
44
+
45
+ .. doctest::
46
+
47
+ >>> from testcontainers.mailpit import MailpitUser
48
+
49
+ >>> users = [
50
+ ... MailpitUser("jane", "secret"),
51
+ ... MailpitUser("ron", "pass2"),
52
+ ... ]
53
+
54
+ >>> for user in users:
55
+ ... print(user.username, user.password)
56
+ ...
57
+ jane secret
58
+ ron pass2
59
+
60
+ >>> username, password = users[0]
61
+
62
+ >>> print(username, password)
63
+ jane secret
64
+ """
37
65
38
66
username : str
39
67
password : str
@@ -47,11 +75,12 @@ class MailpitContainer(DockerContainer):
47
75
user/password.
48
76
49
77
Options:
50
- - ``require_tls = True`` forces the use of SSL
51
- - ``users = [MailpitUser("jane", "secret"), MailpitUser("ron", "pass2")]``
78
+
79
+ * ``require_tls = True`` forces the use of SSL
80
+ * ``users = [MailpitUser("jane", "secret"), MailpitUser("ron", "pass2")]`` \
52
81
only allows login with ``jane:secret`` or ``ron:pass2``
53
82
54
- Example :
83
+ Simple example :
55
84
56
85
.. doctest::
57
86
@@ -69,6 +98,27 @@ class MailpitContainer(DockerContainer):
69
98
... code, _ = server.login("any", "auth")
70
99
... assert code == 235 # authentication successful
71
100
... # use server.sendmail(...) to send emails
101
+
102
+ Example with auth and forced TLS:
103
+
104
+ .. doctest::
105
+
106
+ >>> import smtplib
107
+
108
+ >>> from testcontainers.mailpit import MailpitContainer, MailpitUser
109
+
110
+ >>> users = [MailpitUser("jane", "secret"), MailpitUser("ron", "pass2")]
111
+
112
+ >>> with MailpitContainer(users=users, require_tls=True) as mailpit_container:
113
+ ... host_ip = mailpit_container.get_container_host_ip()
114
+ ... host_port = mailpit_container.get_exposed_smtp_port()
115
+ ... server = smtplib.SMTP_SSL(
116
+ ... mailpit_container.get_container_host_ip(),
117
+ ... mailpit_container.get_exposed_smtp_port(),
118
+ ... )
119
+ ... code, _ = server.login("jane", "secret")
120
+ ... assert code == 235 # authentication successful
121
+ ... # use server.sendmail(...) to send emails
72
122
"""
73
123
74
124
def __init__ (
0 commit comments